I want to override the templates/admin/change_list_results.html and templates/admin/change_list.html templates for just one of my models. How do I tell the admin to differentiate this model from all the others in my app and render a different change template than the default? If I just edit change_list_results.html then all the models in the admin views will reflect my changes.
You can, see documentation here.
The short version is that you need a custom template at admin/your-app-name/your-model-name/change_list.html
in your template path. It can be in an an app or in your root template directory.
The one catch is that Django needs to find it before it finds the default "admin/change_list.html" in django.contrib.admin
. If it's in an app, make sure that app is listed before django.contrib.admin
in INSTALLED_APPS
. I usually just put admin template overrides in my root templates folder, since that gets loaded before apps.
IMHO wont work because change_list_results.html is called from a 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 monkey patch that template tag. But import order play a lot in this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With