order_by gives you the SQL upload to the database. You already use this and then chop it. At this point, the results are output to memory. If you want to change your order, you need to use sorting in Python memory for this, rather than ORM sorting in the database.
In your case, Daniel has already given a better solution: since you just want to sort by the same field, but in a different order, just change the list that you have:
qs = Foo.objects.all()[:5] objs = reversed(qs)
If you needed to sort some other field, you should use the sorted () function using a special function:
qs = Foo.objects.all()[:5] objs = sorted(qs, key=lambda o: o.some_other_field)
Ned batchelder
source share