django: Custom template on admin form


Most of the time, the auto generated Django admin forms are pretty sufficient.

Although there are other times when you'd find it helpful to add some information into the form such as "current results" for the polls or current weather trends for the week if looking at a weather station.

To customise the admin template:

  • Create a template file in "templates/admin/appname/model_name/change_form.html"
  • Make it extend "admin/change_form.html"
  • A sample change is:

{% block after_field_sets %}
{% if change %}
You are changing {{ original }}
{% else %}
This is a new objecct
{% endif %}
{% endblock %}

  • Save and refresh to see it take effect.

To see what blocks you can replace, see the folder "django/contrib/admin/templates/".

[ Source ]


  1. Can one customise the template for just a single model?

    1. Yep, this post is for exactly that.

      Replace "appname/model_name" with the app/model of whatever you're trying to replace.


Leave your thoughts ...
If you are having trouble with copy/pasting in comments, you need to sign in or click 'Preview'. For more information about this Firefox bug, see here.

Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog