DEV Community

pooyaalamdari
pooyaalamdari

Posted on

django orm

product - models.py

class Product(models.Model):
    id = models.CharField(max_length=10, primary_key=True)
    title = models.CharField(max_length=225)
    slug = models.SlugField()
    description = models.TextField()
    # 9999.99
    unit_price = models.DecimalField(max_digits=6, decimal_places=2)
    inventory = models.ImageField()
    last_update = models.DateTimeField(auto_now=True)
    # then reference collection class here
    # PROTECT -> if accidentally delete Collection(Parent), PROTECT will protect our all Products (Child)
    collection = models.ForeignKey(Collection, on_delete=models.PROTECT)
    # we use plural because we have multiple promotions
    # many to many
    promotions = models.ManyToManyField(Promotion)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)