from django.db import models class TestModel(models.Model): f = models.IntegerField(null = True, blank = True) # from django.db import connection # print TestModel.objects.exclude(f=5) # print connection.queries # [{'time': '0.002', 'sql': 'SELECT "t_testmodel"."id", "t_testmodel"."f" FROM "t_testmodel" WHERE NOT (("t_testmodel"."f" = 5 AND "t_testmodel"."f" IS NOT NULL)) LIMIT 21'}]