I have two models called User and Transaction . Here i want to get the all the users with total sum of the transaction amount where status is succe
User
Transaction
For using the subquery, use this:
query=User.objects.annotate(total_spent=Subquery(subquery.values("user")[:1])).order_by("total_spent")