Update doc example for overriding change_form.html
Slightly reworded another related paragraph for clarity, too.
This commit is contained in:
parent
a051a9d929
commit
3f890f8dc7
|
@ -1790,31 +1790,32 @@ Because of the modular design of the admin templates, it is usually neither
|
||||||
necessary nor advisable to replace an entire template. It is almost always
|
necessary nor advisable to replace an entire template. It is almost always
|
||||||
better to override only the section of the template which you need to change.
|
better to override only the section of the template which you need to change.
|
||||||
|
|
||||||
To continue the example above, we want to add a new link next to the ``History``
|
To continue the example above, we want to add a new link next to the
|
||||||
tool for the ``Page`` model. After looking at ``change_form.html`` we determine
|
``History`` tool for the ``Page`` model. After looking at ``change_form.html``
|
||||||
that we only need to override the ``object-tools`` block. Therefore here is our
|
we determine that we only need to override the ``object-tools-items`` block.
|
||||||
new ``change_form.html`` :
|
Therefore here is our new ``change_form.html`` :
|
||||||
|
|
||||||
.. code-block:: html+django
|
.. code-block:: html+django
|
||||||
|
|
||||||
{% extends "admin/change_form.html" %}
|
{% extends "admin/change_form.html" %}
|
||||||
{% load i18n %}
|
{% load i18n admin_urls %}
|
||||||
{% block object-tools %}
|
{% block object-tools-items %}
|
||||||
{% if change %}{% if not is_popup %}
|
<li>
|
||||||
<ul class="object-tools">
|
<a href="{% url opts|admin_urlname:'history' original.pk|admin_urlquote %}" class="historylink">{% trans "History" %}</a>
|
||||||
<li><a href="history/" class="historylink">{% trans "History" %}</a></li>
|
</li>
|
||||||
<li><a href="mylink/" class="historylink">My Link</a></li>
|
<li>
|
||||||
|
<a href="mylink/" class="historylink">My Link</a>
|
||||||
|
</li>
|
||||||
{% if has_absolute_url %}
|
{% if has_absolute_url %}
|
||||||
<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">
|
<li>
|
||||||
{% trans "View on site" %}</a>
|
<a href="{% url 'admin:view_on_site' content_type_id original.pk %}" class="viewsitelink">{% trans "View on site" %}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif%}
|
{% endif%}
|
||||||
</ul>
|
|
||||||
{% endif %}{% endif %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
And that's it! If we placed this file in the ``templates/admin/my_app``
|
And that's it! If we placed this file in the ``templates/admin/my_app``
|
||||||
directory, our link would appear on every model's change form.
|
directory, our link would appear on the change form for all models within
|
||||||
|
my_app.
|
||||||
|
|
||||||
Templates which may be overridden per app or model
|
Templates which may be overridden per app or model
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue