这是我的代码,
data1 = Data.objects.filter(...).annotate(Max('receiver')).order_by('-receiver__max')
data2 = Data.objects.filter(...).annotate(Max('sender')).order_by('-sender__max')
如何在一个查询中组合这两个查询?
答案 0 :(得分:1)
你应该能够很好地结合它,如果你只对最大值感兴趣,那么也不需要order_by
。你应该能做到的;
data = Data.objects.filter(...).annotate(Max('receiver'), Max('sender'))
哪些应该返回类似的内容;
{'receiver__max': 10, 'sender__max': 12}