Sql to Django queryset cheatsheet

Sql QuerySet Notes SELECT count(*) FROM fruit Fruits.objects.count() table count SELECT count(*) FROM fruit WHERE name=’Orange’ Fruits.objects.filter(name__exact=’Orange’).count() count with filter SELECT * FROM fruit WHERE color is NULL Fruits.objects.get(color__isnull=True) filter by null SELECT * FROM fruit WHERE color is NOT NULL Fruits.objects.get(color__isnull=False) filter by null SELECT * FROM fruit WHERE name=’Apple’ Fruits.objects.get(name__exact=’Apple’) case sensitive SELECT

Read on »

Django leaks memory in debug mode.

If you find your program is leaking memory when using Django model then it is most probably because you are in running in debug mode. Django keeps track of the sql statement generated by the model save in debug mode which tends to be the reason behind leak. It is not a problem unless you

Read on »