Version 1 (modified by davidschein@…, 13 years ago) (diff)



Django's admin stuff is great. Often, you would like to just add just a little and you would be all set. For example it would be nice to be able to add links to related data on a change form (detail). With 1 little hack, this is easy. The hack is that you need to copy (if you are on Windows, link on Nixes) the admin template that you want to extend so that the template loader does not get confused.

(Of course, there is probably some simpler mechanism I have not come across or recognized yet, but... live and learn.)


  1. make a directory in your template path named admin_copies
  2. copy change_form.html from your Django install's contrib/admin/templates/admin
  3. create your admin/project_name/model_name/change_form.html: the template loader will look first in your template_dirs before looking in the app directories, i.e. django.contrib.admin.
  4. your change_form.html will look something like:
{% extends "admin_copies/change_form" %}
{% block coltype %}colMS{% endblock %}
{% block sidebar %}
<div id="content-related">
    <div id="navcontainer">
        <ul id="navlist">
            <li><a href="../merge/">Merge {{ }} to another</a></li>
            {% ifequal 1 %}
            <li><a href="/admin/manager/shareholders/{{ }}/">Show shareholder data for {{ }}</a></li>
            {% endifequal %}
{% endblock %}

This makes the layout use a sidebar and populates it with some links for related functions or data.

You need the admin_copies directory because you can not extend admin/change_form because it will never be found--you are editing the very file that overrides it. So you give the template loader another place to look. Hence, the copy.

All very neat and clean.

Attachments (1)

Download all attachments as: .zip

Back to Top