我有一个models类,它计算前一行以在下一行中添加值。它总是显示错误消息“请选择下面的错误”即使我被使用null= True
def BMICal(height, PatientWeight):
Hiin = str(float(height)).split(".")
heightInc = ((((int(Hiin[0]) * 12) + int(Hiin[1])) * 2.54) / 100)
final = PatientWeight/(heightInc*heightInc)
return final
class PatTest(models.Model):
TestId = models.AutoField(primary_key=True)
Patient = models.ForeignKey(Patient, on_delete=models.CASCADE)
BS = models.IntegerField()
BP = models.IntegerField()
PatHeight = models.FloatField()
PatientWeight = models.PositiveIntegerField()
BMI = models.FloatField(null=True)
TEMPA = models.IntegerField()
def clean(self):
self.BMI = BMICal(self.PatHeight, self.PatientWeight)
print(self.BMI)
def __str__(self):
return str(self.TestId)
你需要添加
blank=True
像BMI = models.FloatField(null=True, blank=True)
null
将空值作为NULL存储在数据库中blank
表示该字段允许为空选中null和blank模型字段选项
相关问题 更多 >
编程相关推荐