将不同类别的价格加起来

时间:2019-03-09 11:25:51

标签: python django django-models

我想在“服务”类的“价格”属性中添加“订单”类的“总价值”属性。

class Service(models.Model):
    Handyman = models.ForeignKey(Handyman, on_delete=models.CASCADE)
    name = models.CharField(max_length=500)
    short_description = models.CharField(max_length=500)
    image = models.ImageField(upload_to='service_images/', blank=True)
    price = models.IntegerField(default=0)

class Order(models.Model):
    ORDER = 1
    READY = 2
    ONTHEWAY = 3
    DONE = 4

    STATUS_CHOICES = (
        (ORDER, "Order"),
        (READY, "Ready"),
        (ONTHEWAY, "On the way"),
        (DONE, "Done")
    )
    customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
    Handyman = models.ForeignKey(Handyman, on_delete=models.CASCADE)
    address = models.CharField(max_length=500)
    total = models.IntegerField()
    status = models.IntegerField(choices = STATUS_CHOICES)
    created_at = models.DateTimeField(default = timezone.now)
    picked_at = models.DateTimeField(blank = True, null = True)

    def __str__(self):
        return str(self.id)

0 个答案:

没有答案