1

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?

1 Answer 1

1

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}
Sign up to request clarification or add additional context in comments.

1 Comment

Working perfectly fine. Thank You Sir!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.