models.py 1.0 KB

123456789101112131415161718192021222324252627282930
  1. from django.db import models
  2. import uuid
  3. from django.utils import timezone
  4. class Image(models.Model):
  5. _id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  6. url = models.ImageField(upload_to ='uploads/')
  7. class Good(models.Model):
  8. _id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  9. name = models.CharField('name',default="", max_length = 200,blank=True)
  10. description = models.CharField('description',default="", max_length = 1000,blank=True)
  11. price = models.IntegerField("price", default=0,blank=True)
  12. amount = models.IntegerField("amount", default=0,blank=True)
  13. images = models.ManyToManyField(Image,related_name ="goods", blank = True,through='GoodImage')
  14. createdAt = models.DateTimeField(default=timezone.now)
  15. class GoodImage(models.Model):
  16. image = models.ForeignKey(Image,on_delete=models.CASCADE)
  17. good = models.ForeignKey(Good,on_delete=models.CASCADE,related_name="GoodImages")
  18. order = models.IntegerField(default=1)
  19. class Meta:
  20. ordering = ('order',)