Reputation:
Here's my code,
data1 = Data.objects.filter(...).annotate(Max('receiver')).order_by('-receiver__max')
data2 = Data.objects.filter(...).annotate(Max('sender')).order_by('-sender__max')
How can I combine these 2 queries in just one single Query?
Upvotes: 1
Views: 63
Reputation: 12849
You should be able to combine it quite nicely, and if you're only interested in the max values then there's no need to also order_by
. You should just be able to do;
data = Data.objects.filter(...).annotate(Max('receiver'), Max('sender'))
Which should return something like;
{'receiver__max': 10, 'sender__max': 12}
Upvotes: 1