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 ]

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