Ritu Singh
Problem:
I'm trying to use 'liczba_glosow' field for ordering in Django admin panel. The problem is that the model itself has ordering by "numer_na_liscie" in Meta method and admin uses default ordering and than 'liczba_glosow'. I would like admin to use ONLY order_by("-_liczba_glosow") and bypass default. I can't use simple ordering="liczba_glosow" because this field is created only for admin display purpose and it's not part of a model itself.
According to the above provision, any attempt to disable the default sorting like ordering=None, get_ordering() returning None or empty list doesn't work.
Is there an option to override the default sorting in the admin panel without interfering with the model? I need the default sorting of the model in other parts of the application, so I would prefer to leave it.
Solution:
You can set it to your custom ordering with:
we thus inject an expression in get_queryset, and then we use >.ordering [Django-doc] to use that as ordering.
Answered by: >Willem Van Onsem
Credit: >Stackoverflow
Suggested reads:
>What is data binding in Angular?
>What is microservice architecture, and why is it better than monolithic architecture?
>What makes Python 'flow' with HTML nicely as compared to PHP?
>What to do when MQTT terminates an infinite loop while subscribing to a topic in Python?
>Creating custom required rule - Laravel validation
>How to configure transfers for different accounts in stripe with laravel?
>Laravel Query Solved: Laravel withOnly not restricting the query