장고 옴

3109 단어
제품 - 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)

좋은 웹페이지 즐겨찾기