Updated: Dec. 4, 2010, 12:46 a.m.

Django Notes

Django it is just so incredibly convenient, it is soaked in conceptual integrity and ooozes luxury. Just sit back with a nice cup of coco and start knitting your code. The following is a simple mapping of SQL-knowledge to the ORM mapping a more comprehensive description is available in quering guide.

Fields

all(), values(), values_list()

Where

filter(), get()

Order

order_by()

Limit

SELECT * FROM ... LIMIT 1
Node.objects.all()[0]

SELECT * FROM ... LIMIT 4
Node.objects.all()[:4]

SELECT * FROM ... OFFSET 4 LIMIT 6
Node.objects.all()[4:10]

Aggregates and Grouping

Doing

SELECT name, MAX(date) FROM log_log GROUP by name

sdf

Node.objects.values('name').filter(
  name__icontains=name,
).annotate(date=Max('date')).order_by('name')

Inspect the generated queries

Add:

 from django.db import connection

And inspect the value