I have a very simple query: select * from tbl1 where title not in('asdasd', 'asdasd')
.
How do I translate that to Django? It's like I want the opposite of: Table.objects.filter(title__in=myListOfTitles)
I have a very simple query: select * from tbl1 where title not in('asdasd', 'asdasd')
.
How do I translate that to Django? It's like I want the opposite of: Table.objects.filter(title__in=myListOfTitles)
(this thread is old but still could be googled)
you can use models.Q
with "~" as follows:
Table.objects.filter(~Q(title__in=myListOfTitles))
this method specially is helpful when you have multiple conditions.
Django provides two options.
exclude(<condition>)
filter(~Q(<condition>))
Method 2 using Q() method
>>> from django.db.models import Q
>>> queryset = User.objects.filter(~Q(id__lt=5))