Monday, February 15, 2010

Tiny, neat Django trick

In SQL, you can retrieve a list of records via the "IN" syntax:


   SELECT * FROM mytable WHERE id IN (1,2,3,4,5,6);

Django supports near-identical syntax:


   MyTableModel.objects.filter(id__in=[1,2,3,4,5,6])

nice!

No comments: