【发布时间】:2020-08-03 16:47:08
【问题描述】:
这里定义了两个类,我想对两个模型的不同字段做一些计算。
class A(models.Model):
newspaper = models.CharField(max_length=50)
language = models.CharField(max_length=50, choices=Language)
wh_price = models.DecimalField(max_digits=6,decimal_places=2)
sa_price=models.DecimalField(max_digits=6,decimal_places=2)
class B(models.Model):
added_date = models.DateField(max_length=32,auto_now_add=True)
newspaper = models.ForeignKey(Newspaper,on_delete=models.CASCADE)
qty=models.IntegerField(default=0)
qty_return =models.IntegerField(default=0)
total = models.DecimalField(max_digits=6,decimal_places=2)
total(来自 B)= wh_price(来自 A)* qty(来自 B)
【问题讨论】:
-
您能否正确缩进代码,同时指定您想要的什么。也许包括一些样本数据和一些样本输出。
-
报纸是外键 模型 A 是报纸。所以当我给报纸和数量的时候。 total 必须自动计算保存总列。所以这实际上需要