简体   繁体   English

Django Order_By Datetime

[英]Django Order_By Datetime

I have a model with a DateTime field, called Game. 我有一个带有DateTime字段的模型,称为Game。

When I called Game.objects.order_by('-date'), it mostly works. 当我调用Game.objects.order_by('-date')时,它通常可以正常工作。 However, if two games have the same datetime, then they appear in reverse chronological order (in ascending pk order). 但是,如果两个游戏具有相同的日期时间,则它们将以相反的时间顺序出现(以pk升序排列)。 IE, if you enter game1, then game2, game1 will appear as the most recent game. IE,如果您输入game1,然后输入game2,则game1将显示为最新游戏。 Is there any way to reverse this? 有什么办法可以扭转这种情况吗?

如果您希望子订单也要反转,则应明确声明:

Game.objects.order_by('-date', '-pk')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM