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)
|
|
|
|
image = models.ImageField(upload_to="brands", blank=True, null=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class ProductColor(models.Model):
|
|
|
|
color = models.CharField(max_length=20)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.color
|
|
|
|
|
|
|
|
|
|
|
|
class ProductStorage(models.Model):
|
|
|
|
storage = models.CharField(max_length=20)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.storage
|
|
|
|
|
|
|
|
|
|
|
|
class Product(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
2023-05-03 14:09:38 +09:00
|
|
|
brand = models.ForeignKey(
|
|
|
|
Brand, on_delete=models.CASCADE, related_name="products"
|
|
|
|
)
|
|
|
|
color = models.ManyToManyField(
|
|
|
|
"ProductColor", blank=True, related_name="products"
|
|
|
|
)
|
|
|
|
storage = models.ManyToManyField(
|
|
|
|
"ProductStorage", blank=True, 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
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class Post(models.Model):
|
|
|
|
STATUS_CHOICES = (
|
|
|
|
("s", "selling"),
|
|
|
|
("r", "reserved"),
|
|
|
|
("d", "done"),
|
|
|
|
)
|
2023-05-03 14:09:38 +09:00
|
|
|
product = models.ForeignKey(
|
|
|
|
Product, on_delete=models.CASCADE, related_name="posts"
|
|
|
|
)
|
2023-05-01 20:49:25 +09:00
|
|
|
color = models.ForeignKey(ProductColor, on_delete=models.CASCADE)
|
|
|
|
storage = models.ForeignKey(ProductStorage, on_delete=models.CASCADE)
|
|
|
|
price = models.IntegerField()
|
|
|
|
text = models.TextField()
|
|
|
|
author = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
|
|
|
status = models.CharField(
|
|
|
|
max_length=1, choices=STATUS_CHOICES, default="s"
|
|
|
|
)
|
|
|
|
written_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.product.name
|
|
|
|
|
|
|
|
|
|
|
|
class Image(models.Model):
|
2023-05-03 14:09:38 +09:00
|
|
|
post = models.ForeignKey(
|
|
|
|
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)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.post.product.name
|