Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django not like statement

how to use not like in django queries

    Model.objects.filter(keywords not like "null" or "undefined")

       select * from model where keywords not like "%undefined%"  or keywords not like "%null%";
like image 413
Rajeev Avatar asked Nov 16 '10 10:11

Rajeev


People also ask

How do you say not equal to in Django?

To answer your specific question, there is no "not equal to" but that's probably because django has both "filter" and "exclude" methods available so you can always just switch the logic round to get the desired result.

IS NOT NULL Django?

The Django convention is to use the empty string, not NULL. The default values of null and blank are False. Also there is a special case, when you need to accept NULL values for a BooleanField , use NullBooleanField instead.

What is QuerySet in Django?

A QuerySet is a collection of data from a database. A QuerySet is built up as a list of objects. QuerySets makes it easier to get the data you actually need, by allowing you to filter and order the data.


1 Answers

use the exclude function and Q objects

Model.objects.exclude(Q(keyword__contains='undefined') | Q(keyword__contains='null'))
like image 139
luc Avatar answered Sep 24 '22 18:09

luc