what I’m trying to do is this:
-
get the 30 Authors with highest score (
Author.objects.order_by('-score')[:30]) -
order the authors by
last_name
Any suggestions?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What about
In Django 1.4 and newer you can order by providing multiple fields.
Reference: https://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by
order_by(*fields)
By default, results returned by a
QuerySetare ordered by the ordering tuple given by theorderingoption in the model’s Meta. You can override this on a per-QuerySet basis by using theorder_bymethod.Example:
The result above will be ordered by
scoredescending, then bylast_nameascending. The negative sign in front of"-score"indicates descending order. Ascending order is implied.