开发者

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')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜