In Django model QuerySets, I see that there is a __gt
and __lt
for comparative values, but is there a __ne
or !=
(not equals)? I want to filter out using a not equals. For example, for
Model:
bool a;
int x;
I want to do
results = Model.objects.exclude(a=True, x!=5)
The !=
is not correct syntax. I also tried __ne
.
I ended up using:
results = Model.objects.exclude(a=True, x__lt=5).exclude(a=True, x__gt=5)
a=true
first and then applies thex=5
filter on the remaining. The intended query required only those witha=true
andx!=5
. The difference being that all those witha=true
andx=5
are also filtered out. – Mitchell van Zuylen