Changes between Initial Version and Version 1 of ExtendingAdminTemplates


Ignore:
Timestamp:
Apr 6, 2006, 3:16:12 PM (19 years ago)
Author:
davidschein@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • 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. 
     3
     4(Of course, there is probably some simpler mechanism I have not come across or recognized yet, but... live and learn.)
     5
     6
     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:
     13
     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 {{ form.data.id }} to another</a></li>
     22            {% ifequal form.data.is_shareholder 1 %}
     23            <li><a href="/admin/manager/shareholders/{{ form.data.id }}/">Show shareholder data for {{ form.data.id }}</a></li>
     24            {% endifequal %}
     25        </ul>
     26    </div>
     27</div>
     28{% endblock %}
     29   }}}
     30   This makes the layout use a sidebar and populates it with some links for related functions or data.
     31
     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.
     33
     34All very neat and clean.   
     35
     36
Back to Top