HiPhone_BE/market/models.py

76 lines
1.9 KiB
Python
Raw Permalink Normal View History

2023-05-01 20:49:25 +09:00
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)
2023-11-13 19:52:35 +09:00
brand = models.ForeignKey(
Brand,
on_delete=models.CASCADE,
related_name="products",
)
2023-05-03 13:53:40 +09:00
release_date = models.DateField(blank=True, null=True)
2023-05-01 20:49:25 +09:00
2023-05-18 10:03:47 +09:00
class Meta:
ordering = ["-release_date"]
2023-05-01 20:49:25 +09:00
def __str__(self):
return self.name
2023-11-09 19:41:37 +09:00
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)
2023-05-01 20:49:25 +09:00
class Post(models.Model):
product = models.ForeignKey(
2023-11-09 19:41:37 +09:00
Product,
on_delete=models.CASCADE,
related_name="posts",
)
2023-05-01 20:49:25 +09:00
price = models.IntegerField()
text = models.TextField()
2023-10-31 14:25:16 +09:00
author = models.ForeignKey(
User, on_delete=models.SET_NULL, null=True, related_name="posts"
)
2023-11-09 19:41:37 +09:00
item_issues = models.OneToOneField(
ItemIssues, on_delete=models.CASCADE, null=True, related_name="post"
2023-05-01 20:49:25 +09:00
)
2023-11-09 19:41:37 +09:00
done = models.BooleanField(default=False)
2023-05-01 20:49:25 +09:00
written_at = models.DateTimeField(auto_now_add=True)
2023-05-18 10:03:47 +09:00
class Meta:
ordering = ["-written_at"]
2023-05-01 20:49:25 +09:00
def __str__(self):
2023-06-16 16:36:27 +09:00
return f"{self.product} : {self.author} : {self.written_at}"
2023-05-01 20:49:25 +09:00
class Image(models.Model):
post = models.ForeignKey(
2023-11-09 19:41:37 +09:00
Post,
on_delete=models.CASCADE,
related_name="images",
)
2023-05-01 20:49:25 +09:00
image = models.ImageField(upload_to="images", blank=True, null=True)
2023-06-16 16:36:27 +09:00
class Meta:
2023-06-20 19:01:19 +09:00
ordering = ["pk"]
2023-06-16 16:36:27 +09:00
2023-05-01 20:49:25 +09:00
def __str__(self):
2023-06-16 16:36:27 +09:00
return f"{self.post}"