models.py 1.1 KB

12345678910111213141516171819202122232425262728
  1. from django.db import models
  2. from goods.models import Good
  3. from django.utils import timezone
  4. from django.contrib.auth import get_user_model
  5. import uuid
  6. class Order(models.Model):
  7. _id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  8. createdAt = models.DateTimeField(default=timezone.now)
  9. status = models.IntegerField("status", default=1)
  10. price = models.IntegerField("price", default=1)
  11. delivery = models.CharField("delivery",max_length=50,default="-")
  12. owner = models.ForeignKey(get_user_model(),related_name="orders",on_delete=models.SET_NULL, null = True)
  13. class OrderGood(models.Model):
  14. _id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  15. good = models.ForeignKey(Good, on_delete=models.CASCADE,related_name="orderGoods")
  16. price = models.IntegerField("price", default=1)
  17. count = models.IntegerField("count", default=1)
  18. order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name="orderGoods",blank=True,null=True)
  19. createdAt = models.DateTimeField(default=timezone.now)