Add related name on models in market app

This commit is contained in:
jhyns 2023-05-03 14:09:38 +09:00
parent c2c007aef7
commit 42deebb758

View File

@ -27,9 +27,15 @@ class ProductStorage(models.Model):
class Product(models.Model):
name = models.CharField(max_length=50)
brand = models.ForeignKey(Brand, on_delete=models.CASCADE)
color = models.ManyToManyField("ProductColor", blank=True)
storage = models.ManyToManyField("ProductStorage", blank=True)
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"
)
release_date = models.DateField(blank=True, null=True)
def __str__(self):
@ -42,7 +48,9 @@ class Post(models.Model):
("r", "reserved"),
("d", "done"),
)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
product = models.ForeignKey(
Product, on_delete=models.CASCADE, related_name="posts"
)
color = models.ForeignKey(ProductColor, on_delete=models.CASCADE)
storage = models.ForeignKey(ProductStorage, on_delete=models.CASCADE)
price = models.IntegerField()
@ -58,7 +66,9 @@ class Post(models.Model):
class Image(models.Model):
post = models.ForeignKey(Post, on_delete=models.CASCADE)
post = models.ForeignKey(
Post, on_delete=models.CASCADE, related_name="images"
)
image = models.ImageField(upload_to="images", blank=True, null=True)
def __str__(self):