Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Extend admin index

I wish to make some modifications to the Django admin interface (specifically, remove the "change" link, while leaving the Model name as a link to the page for changes to the instances). I can achieve this by copying and pasting index.html from the admin application, and making the modifications to the template, but I would prefer to only override the offending section by extending the template - however I am unsure how to achieve this as the templates have the same name. I am also open to alternative methods of achieving this effect. (django 1.7, python 3.4.1)

like image 331
James Avatar asked Jan 09 '23 20:01

James


2 Answers

Worked it out - I set admin.site.index_template = "my_index.html" in admin.py, and then the my_index template can inherit from admin/index.html without a name clash.

like image 156
James Avatar answered Jan 16 '23 22:01

James


Might be cleaner to override the index_template for AdminSite:

from django.contrib.admin.sites import AdminSite
AdminSite.index_template = '...'

Though again, that might be made more external-code-friendly by either: changing this on a custom instance before binding, or subclassing a custom AdminSite and overriding there, and registering that custom AdminSite instead.

Relevant documentation:

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#root-and-login-templates

Edit: To clarify - this would allow you to just override the section you're changing in the template, and so inherit any upstream changes.

like image 33
tr00st Avatar answered Jan 16 '23 20:01

tr00st