I want to apply a default filter value on a field ModelAdmin in django.
I have a Model admin for the User
model, which displays users. The user has a m2m to an Account
model, so I am adding in the ModelAdmin:
class CustomUserAdmin(UserAdmin):
list_filters = ('accounts')
In the filter I want it to give a default selected value, if nothing is selected. However I still want to give the user the option to revert to the default All
option.
So far all the solutions that I found, prevent reverting to the All
option. For example this answer.
I am thinking, that maybe chaining the link on the side menu to include the desired filter option in the query parameters. Is this doable? I can see in the source code for admin/app_list.html
(source code), that the URL comes from model.admin_link
, but I cant find any documentation for changing it.