Django - check for null in database

By: Varghese Chacko 1 year, 3 months ago

isnull

In django, the NULL valuein the database field is tested with field lookup isnull It takes either True or False, which correspond to SQL queries of IS NULL and IS NOT NULL, respectively.

Example:

Entry.objects.filter(pub_date__isnull=True)

SQL equivalent:

SELECT * from enty WHERE pub_date IS NULL;