Django admin override change_list_results.html for some models only

I want to override the templates / admin / change _list_results.html and templates / admin / change_list.html for just one of my models. How do I tell the administrator to distinguish this model from everyone else in my application and display a different change pattern than the default? If I just edit the change_list_results.html file, then all the models in the admin views will reflect my changes.

+4
source share
2 answers

You can see the documentation here .

The short option is that you need a custom template in admin/your-app-name/your-model-name/change_list.html in your template. It can be in the application or in the root directory of the templates.

The only thing Django needs to find before it finds the default value "admin / change_list.html" in django.contrib.admin . If this is an application, make sure the application is listed before django.contrib.admin in INSTALLED_APPS . Usually, I just add admin template overrides to the root templates folder, as this loads before applications.

+3
source

IMHO does not work because change_list_results.html is called from template_tag → result_list.

https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/change_list.html#L91

https://github.com/django/django/blob/65cf82bd08631a7aa8d9dd007b2527476fa3304f/django/contrib/admin/templatetags/admin_list.py#L288

I want to see what happens if you override or patch-patch the template tag. But the import order plays a lot in this.

+2
source

All Articles