3

I need to edit the template shown for editing a specific user. I need to display some additional data that doesn't fit in with an include-style.

I apologise for the short question... but that's pretty much all there is at the moment.

Gavin Miller
  • 43,168
  • 21
  • 122
  • 188
Oli
  • 235,628
  • 64
  • 220
  • 299
  • What do you mean "doesnt fit in"? Doesnt display? – Mez Nov 03 '09 at 18:07
  • I mean it's not form-data - it's report data. I want to show some user activity from other models *on* the User page. – Oli Nov 03 '09 at 18:09

3 Answers3

6

If you can't accomplish what you want with just subclassing admin.ModelAdmin, you can create a directory "admin/auth" in your template directory and put a "change_form.html" in there. In this template you can override blocks that are available e.g. {% block after_related_objects %}.

Have a look at django/contrib/templates/admin/change_form.html to see how they do stuff, e.g.:

{% block extrahead %}{{ block.super }}
<script type="text/javascript" src="../../../jsi18n/"></script>
{{ media }}
{% endblock %}

appending stuff to the extrahead block.

stefanw
  • 10,456
  • 3
  • 36
  • 34
  • 1
    you probably need to add it in TEMPLATE_DIR/admin/auth/user if it's only specific to a certain user ;) – Mez Nov 03 '09 at 18:17
  • Top stuff. For bonus points, any idea how to get the current user? Ie the object that is being processed. – Oli Nov 03 '09 at 18:40
  • 2
    {{ original }} is the object being edited. For instance, {{ original.id }} – Gabriel Ross Nov 03 '09 at 18:51
2

Have a look at

django/contrib/admin/templates/admin/auth/user/

This should contain a couple of templates for modifying the users.

You can override these by copying them to TEMPLATE_DIR/admin/auth and then changing them.

Also, have a look @ django/contrib/admin/templates/admin/change_form.html

This is the file you'd copy and change (to TEMPLATE_DIR/admin/auth/user/) to override the change form for that model.

Mez
  • 24,430
  • 14
  • 71
  • 93
0

I'd override the admin/auth/user/change_form.html template and add a custom template tag to handle whatever queries need to be done to fetch the data you need to display.

Josh Ourisman
  • 1,078
  • 1
  • 9
  • 16