在Django模型QuerySets中,我看到比较值存在__gt和__lt,但是存在__ne// !=/ <>(不等于?)。
我想使用不等于过滤掉:
例:
Model:
bool a;
int x;
我想要
results = Model.objects.exclude(a=true, x!=5)
在!=不正确的语法。我试过__ne,<>。
我最终使用:
results = Model.objects.exclude(a=true, x__lt=5).exclude(a=true, x__gt=5)
a=true首先排除所有内容,然后x=5对其余内容应用过滤器。预期查询仅需要使用a=true和的查询x!=5。区别在于所有带有a=true和的x=5对象也被过滤掉了。