TypeError: __str__ returned non-string (type WebStepInfo)
错误代码:
class CaseStep(models.Model): id = models.AutoField(primary_key=True) casetep = models.ForeignKey(WebStepInfo, on_delete=models.CASCADE, verbose_name="测试步骤") casedata = models.chaCharField("测试数据", max_length=200, default='null') stepresult = models.BooleanField("测试结果", default=False) webcase = models.ForeignKey(WebCase, on_delete=models.CASCADE, verbose_name="所属用例") update_time = models.DateTimeField("最近更改时间", auto_now=True) create_time = models.DateTimeField("创建时间", auto_now_add=True) class Meta: db_table = "CaseInfo" def __str__(self): return self.casetep
在向该表中添加数据时提示__str__ returned non-string (type WebStepInfo),原因是models 中的__str(self)函数返回的都是chaCharField类型,而代码中返回的是(type WebStepInfo)
更改代码:
def __str__(self): return self.casetep.stepname