class PO(models.Model)
qty = models.IntegerField(null=True)
cost = models.IntegerField(null=True)
total = qty * cost
Run Code Online (Sandbox Code Playgroud)
我将如何解决total = qty * cost
上述问题.我知道它会导致错误,但不知道如何处理这个问题.
Ahs*_*san 37
您可以创建total
一个property
字段,查看文档
class PO(models.Model)
qty = models.IntegerField(null=True)
cost = models.IntegerField(null=True)
def _get_total(self):
"Returns the total"
return self.qty * self.cost
total = property(_get_total)
Run Code Online (Sandbox Code Playgroud)
rec*_*hie 13
class PO(models.Model)
qty = models.IntegerField(null=True)
cost = models.IntegerField(null=True)
@property
def total(self):
return self.qty * self.cost
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13974 次 |
最近记录: |