Changes between Initial Version and Version 1 of ExtendingAdminTemplates

04/06/2006 03:16:12 PM (14 years ago)



  • ExtendingAdminTemplates

    v1 v1  
     1=== Intro ===
     2Django'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. 
     4(Of course, there is probably some simpler mechanism I have not come across or recognized yet, but... live and learn.)
     7=== Steps ===
     8 1. make a directory in your template path named ``admin_copies``
     9 2. copy change_form.html from your Django install's contrib/admin/templates/admin
     10 3. create your admin/project_name/model_name/change_form.html:
     11    the template loader will look first in your template_dirs before looking in the app directories, i.e. django.contrib.admin.
     12 4. your change_form.html will look something like:
     14   {{{
     15{% extends "admin_copies/change_form" %}
     16{% block coltype %}colMS{% endblock %}
     17{% block sidebar %}
     18<div id="content-related">
     19    <div id="navcontainer">
     20        <ul id="navlist">
     21            <li><a href="../merge/">Merge {{ }} to another</a></li>
     22            {% ifequal 1 %}
     23            <li><a href="/admin/manager/shareholders/{{ }}/">Show shareholder data for {{ }}</a></li>
     24            {% endifequal %}
     25        </ul>
     26    </div>
     28{% endblock %}
     29   }}}
     30   This makes the layout use a sidebar and populates it with some links for related functions or data.
     32You 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.
     34All very neat and clean.   
Back to Top