0
我的代碼存在一些問題。我看着必須解決它,但我沒有發現類似的問題。我想多個,然後總結一些字段值,但我從標題中得到錯誤。必須解決這個問題嗎?我想這是數據類型的問題,但我不知道如何定義方程。請幫幫我。Django錯誤:不支持的操作數類型爲*:'NoneType'和'float'
class Bill(models.Model):
date = models.DateField(default=datetime.now())
tax = models.FloatField(default=0.20)
priceNoTax = models.IntegerField()#integer that I get from other class
priceTax = models.FloatField()
idAccount = models.ForeignKey(Account, on_delete=models.CASCADE, verbose_name="Account")
def save(self, *args, **kwargs):
if self.priceTax is None:
self.priceTax = self.priceNoTax+(self.priceNoTax*self.tax)#here is an error
super(Bill, self).save(*args, **kwargs)
def __str__(self):
return self.date
非常感謝!
您已檢查'priceTax'是否爲None,但您沒有檢查'priceNoTax'是否爲None,它顯然是。 –