Re: Conditional Order By

2019-11-15 Thread Simon Charette
Hello there, You'll want to use Coalesce[0] for this purpose. Model1.objects.order_by(Coalesce('effectual_rating', 'rating').desc()) Cheers, Simon [0] https://docs.djangoproject.com/en/2.2/ref/models/database-functions/#coalesce Le vendredi 15 novembre 2019 13:32:46 UTC-5, Kev H a écrit : > >

Conditional Order By

2019-11-15 Thread Kev H
I have a model where a field can be null (and is most of the time). However, I need to order_by this both this field and another field (the 2nd field is never null) so that the results would be sorted by from high to low (1st based on the possible null field if it is not null and then by the 2