django-queryset-5

Last Updated :
Discuss
Comments

When sorting products by price in descending order and then by name in ascending order for consistent tie handling, which order_by call is correct?

Product.objects.order_by('-price', 'name') which applies name as the secondary sort

Product.objects.order_by('name', '-price') which prioritizes name instead of price

Product.objects.order_by('price').reverse('name') which is not valid usage

Product.objects.order_by('-price' + 'name') which treats the fields as a single string

Tags:
Share your thoughts in the comments