diff --git a/market/models.py b/market/models.py index 61465ab..c2dcacd 100644 --- a/market/models.py +++ b/market/models.py @@ -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):