Related Field got invalid lookup: icontains

搜索栏使用外键

问题描述:

Related Field got invalid lookup: icontains

解决方法
image.png

class HistoryTask(models.Model):
    taskId = models.ForeignKey(PhoneInfo, models.SET_NULL,
                               to_field='taskId',
                               null=True, verbose_name="任务Id",
                               default=None)
    functionName = models.CharField("业务场景", max_length=20, help_text="业务场景名")
    historyContent = models.TextField("任务记录", blank=True, help_text="任务执行步骤记录")

    createTime = models.DateTimeField('创建时间', blank=True, null=True)
    historyId = models.CharField('历史记录Id', max_length=40, unique=True, default=None)

    def __str__(self):
        return str(self.historyId)

    class Meta:
        verbose_name = '历史记录'
        verbose_name_plural = verbose_name


class RunStep(models.Model):
    sId = models.ForeignKey(HistoryTask, on_delete=models.CASCADE, to_field='historyId')
    num = models.IntegerField('步骤', default=0)
    desc = models.CharField("描述", max_length=50, default='')
    req = models.TextField("请求", blank=True, help_text="执行步骤", null=True)
    response = models.TextField("响应", blank=True, help_text="请求响应", null=True)
    others = models.TextField("其他信息", blank=True, null=True)
    createTime = models.DateTimeField('创建时间', blank=True, null=True)

    def __str__(self):
        return self.desc

    class Meta:
        ordering = ('createTime',)
image.png

你可能感兴趣的:(Related Field got invalid lookup: icontains)