Archives: April 2011

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 »