【问题标题】:TypeError: unsupported operand type(s) for |: 'bool' and 'Q' [closed]TypeError:不支持的操作数类型|:'bool'和'Q'[关闭]
【发布时间】:2015-03-27 21:25:48
【问题描述】:

我正在运行 Django 1.7,并且在尝试执行以下操作时收到 TypeError: unsupported operand type(s) for |: 'bool' and 'Q'

class PersonList(generic.ListView):
    template_name = "persons/list.html"
    model = Person
    queryset = Person.objects.filter(Q(field1__isnull=True | Q(field2__isnull=True)))

【问题讨论】:

    标签: django django-q


    【解决方案1】:

    在示例代码中,括号不在使用 models.Q 时应该在的位置。

    解决方案:

    Person.objects.filter(Q(field1__isnull=True) | Q(field2__isnull=True))
    

    注意右括号。

    【讨论】:

      猜你喜欢
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 2018-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      • 2011-03-08
      相关资源
      最近更新 更多