Create a field whose value is a calculation of other fields' values

前端 未结 2 1560
长发绾君心
长发绾君心 2020-12-14 18:11
class PO(models.Model)
    qty = models.IntegerField(null=True)
    cost = models.IntegerField(null=True)
    total = qty * cost

How will I solve <

2条回答
  •  情话喂你
    2020-12-14 18:51

    Justin Hamades answer

    class PO(models.Model)
        qty = models.IntegerField(null=True)
        cost = models.IntegerField(null=True)
    
        @property
        def total(self):
            return self.qty * self.cost
    

提交回复
热议问题