1

我有以下内容:

appleCreated = Apple.objects.filter(fruit=fruit.id).latest().created
bananaCreated = Banana.objects.filter(fruit=fruit.id).latest().created
lemonCreated = Lemon.objects.filter(fruit=fruit.id).latest().created
orangeCreated = Orange.objects.filter(fruit=fruit.id).latest().created

.created一个models.DateTimeField()

我需要在四个中找到最新的datetime(我不需要知道它是哪一个)。我知道我需要使用.sort(...),或者sorted(...)文档太密集了我不明白key=lambdaitem:item[0]key=itemgetter(0)WTF 之类的东西!?!?!

4

1 回答 1

7

我不确定我是否理解问题,但不应该

max(appleCreated, bananaCreated, lemonCreated, orangeCreated)

够了吗?

于 2013-03-21T18:05:46.177 回答