Is there any way to override admin templates with different files depending on Django version?
I’ve copied admin/index.hml from Django admin templates, to achieve this: Django admin, hide a model, but there are changes in that template in different versions of Django, and sometimes the page breaks (specially with the deprecation of ADMIN_MEDIA_PREFIX in Django 1.4)
I want to install my site in many servers with different versions of Django, but using just one unified code that notices the version automatically. Is that possible?
I’ve checked Django documentation, but I haven’t found anything about this.
The
ModelAdminclass has various template settings that you can specify in subclasses. In Django 1.3 these are (atdjango.contrib.admin.options, line 271):Similarly,
AdminSitehas various template settings (atdjango.contrib.admin.sites, line 35):You can override these for subclasses or specify them in a central location in your code (e.g., a
__init__.pyfile). For example:You can then vary the templates based on the current Django version. You may need to check what the code looks like in earlier Django versions as I haven’t checked if all these variables are present in earlier Django admin code.