I have a Django model for Cat
which has a foreign key Dog
. The Dog
model has a date key timestamp
. I want to order the cats, using Cat.objects.order_by
, according to the timestamps of their respective dogs. How do I do that?
views:
34answers:
1
+2
A:
Use the double-underscore syntax.
Cat.objects.order_by('dog__timestamp')
Daniel Roseman
2009-10-11 11:32:09