开发者

Complex ordering in Django

开发者 https://www.devze.com 2022-12-08 19:18 出处:网络
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

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

精彩评论

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