Answer the question
In order to leave comments, you need to log in
How to efficiently sort a QuerySet?
Hello! There is a QuerySet that stores the number of likes for each group in the social network. The number of likes is initialized as a @property for the Django model. My task is to sort this QuerySet in descending order (most likes come first). I am using code like this:
sorted_groups = sorted(queryset, key=lambda g: (-g.posts_likes))
Answer the question
In order to leave comments, you need to log in
Digging is in the direction of sorting by the DBMS. Your question has already been asked here .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question