如何按日期时间对两个聚合列表排序?

2024-10-03 17:21:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我将两个不同的列表合并在一起。如何按日期/时间排序

foo = get_list_or_404(Comments, equoes=user) 
foo2 = get_list_or_404(Comments, User=user) 
info = (foo+foo2) 
for x in info: 
print(x.dt)

(编辑:回答了我自己的问题:info=sorted(info,key=lambda time:time.dt))

我要找的东西都在打印件上,但我需要按时间排序。我该怎么办

(这是它的打印方式,最后两个来自添加的列表。)

2019-05-03 17:12:55.611679+00:00
2019-05-03 17:58:08.319295+00:00
2019-05-03 18:13:19.608188+00:00
2019-05-03 15:06:43.242201+00:00
2019-05-03 14:47:19.166391+00:00

Tags: orinfo列表getfootime排序时间
1条回答
网友
1楼 · 发布于 2024-10-03 17:21:35

foofoo2Queryset(/同一型号)型号。所以,可以使用queryset的^{}方法

info.order_by('dt')

其中,dt是日期或日期时间字段

相关问题 更多 >