Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Last active September 27, 2019 09:11
Show Gist options
  • Save kezabelle/d69c9c1fb8af48bc2b3106042d064700 to your computer and use it in GitHub Desktop.
Save kezabelle/d69c9c1fb8af48bc2b3106042d064700 to your computer and use it in GitHub Desktop.
discussing excluding nullable charfields with gcbirzan on #django IRC
>>> class TestModel(models.Model):
... test_field = models.CharField(blank=True, null=True)
... class Meta:
... app_label="test"
>>> TestModel.objects.exclude(test_field='').query.__str__()
'SELECT "test_testmodel"."id", "test_testmodel"."test_field" FROM "test_testmodel" WHERE NOT ("test_testmodel"."test_field" = AND "test_testmodel"."test_field" IS NOT NULL)'
>>> import django
>>> django.VERSION
(2, 2, 4, 'final', 0)
>>> from django.conf import settings
>>> settings.DATABASES
{'default': {'ENGINE': 'django.db.backends.sqlite3', ... }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment