There is the django order by method, here is an example:
Purchase.objects.all().order_by(F('price').desc(nulls_last=True))
This will order by the field price with the additional constraint to have all nulls as last.
I want something slightly different, take this example:
- I have a queryset of
Purchasewith the following prices in THIS EXACT ORDER:[5, None, 13, None, 2] - I want to order by so the result is like this
[5, 13, 2, None, None]
Basically I am looking for a way to simply move all instances where price=None at the end, not affecting the order of the rest of the elements in the queryset.
The method in the example at the top would also sort the rest of the elements in descendent order which I do no want.
Any help appreciated if this is even possible.