Add related name on models in market app
This commit is contained in:
parent
c2c007aef7
commit
42deebb758
@ -27,9 +27,15 @@ class ProductStorage(models.Model):
|
|||||||
|
|
||||||
class Product(models.Model):
|
class Product(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
brand = models.ForeignKey(Brand, on_delete=models.CASCADE)
|
brand = models.ForeignKey(
|
||||||
color = models.ManyToManyField("ProductColor", blank=True)
|
Brand, on_delete=models.CASCADE, related_name="products"
|
||||||
storage = models.ManyToManyField("ProductStorage", blank=True)
|
)
|
||||||
|
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)
|
release_date = models.DateField(blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@ -42,7 +48,9 @@ class Post(models.Model):
|
|||||||
("r", "reserved"),
|
("r", "reserved"),
|
||||||
("d", "done"),
|
("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)
|
color = models.ForeignKey(ProductColor, on_delete=models.CASCADE)
|
||||||
storage = models.ForeignKey(ProductStorage, on_delete=models.CASCADE)
|
storage = models.ForeignKey(ProductStorage, on_delete=models.CASCADE)
|
||||||
price = models.IntegerField()
|
price = models.IntegerField()
|
||||||
@ -58,7 +66,9 @@ class Post(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class Image(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)
|
image = models.ImageField(upload_to="images", blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user