Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django equivalent of SQL not in

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)

like image 420
Ali Avatar asked Jan 25 '12 13:01

Ali


People also ask

Is Django same as SQL?

Django and SQL are not replacements for one another, Django is a web framework as a whole, designed to develop web applications, and SQL is a language to query databases.

What is exclude in Django?

Django's exclude () method basically returns a new QuerySet containing the objects that do not match the given parameter.

What is Django SQL?

Django creates a file with any new changes and stores the file in the /migrations/ folder. Next time you run py manage.py migrate Django will create and execute an SQL statement, based on the content of the new file in the migrations folder.


1 Answers

try using exclude

Table.objects.exclude(title__in=myListOfTitles) 
like image 61
JamesO Avatar answered Sep 29 '22 00:09

JamesO