Complex ordering in Django
I have a Django model for Cat
wh开发者_如何学编程ich 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?
Use the double-underscore syntax.
Cat.objects.order_by('dog__timestamp')
精彩评论