76 lines
1.9 KiB
Python
76 lines
1.9 KiB
Python
from django.db import models
|
|
|
|
from user.models import User
|
|
|
|
|
|
class Brand(models.Model):
|
|
name = models.CharField(max_length=20)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class Product(models.Model):
|
|
name = models.CharField(max_length=50)
|
|
brand = models.ForeignKey(
|
|
Brand,
|
|
on_delete=models.CASCADE,
|
|
related_name="products",
|
|
)
|
|
release_date = models.DateField(blank=True, null=True)
|
|
|
|
class Meta:
|
|
ordering = ["-release_date"]
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class ItemIssues(models.Model):
|
|
display = models.BooleanField(default=False)
|
|
frame = models.BooleanField(default=False)
|
|
button = models.BooleanField(default=False)
|
|
biometric = models.BooleanField(default=False)
|
|
camera = models.BooleanField(default=False)
|
|
speaker = models.BooleanField(default=False)
|
|
others = models.BooleanField(default=False)
|
|
|
|
|
|
class Post(models.Model):
|
|
product = models.ForeignKey(
|
|
Product,
|
|
on_delete=models.CASCADE,
|
|
related_name="posts",
|
|
)
|
|
price = models.IntegerField()
|
|
text = models.TextField()
|
|
author = models.ForeignKey(
|
|
User, on_delete=models.SET_NULL, null=True, related_name="posts"
|
|
)
|
|
item_issues = models.OneToOneField(
|
|
ItemIssues, on_delete=models.CASCADE, null=True, related_name="post"
|
|
)
|
|
done = models.BooleanField(default=False)
|
|
written_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
ordering = ["-written_at"]
|
|
|
|
def __str__(self):
|
|
return f"{self.product} : {self.author} : {self.written_at}"
|
|
|
|
|
|
class Image(models.Model):
|
|
post = models.ForeignKey(
|
|
Post,
|
|
on_delete=models.CASCADE,
|
|
related_name="images",
|
|
)
|
|
image = models.ImageField(upload_to="images", blank=True, null=True)
|
|
|
|
class Meta:
|
|
ordering = ["pk"]
|
|
|
|
def __str__(self):
|
|
return f"{self.post}"
|