Improve PolymorphicParentAdmin, simplify, fix templates

During the development of django-polymorphic-tree it was discovered that
the PolymorphicParentModelAdmin could actually be made much simpler.
It features a `child_models` attribute now, so there is very little code
needed to actually implement a polymorphic admin now.

Also found various issues which are together fixed in this commit for
pulling.
This commit is contained in:
Diederik van der Boor
2012-07-13 10:32:12 +02:00
parent 2e76811adb
commit b2e308d30c
5 changed files with 136 additions and 47 deletions
@@ -0,0 +1,43 @@
{% extends "admin/change_form.html" %}
{% load i18n admin_modify adminmedia %}
{% load url from future %}
{% block breadcrumbs %}{% if not is_popup %}
<div class="breadcrumbs">
<a href="../../../">{% trans "Home" %}</a> &rsaquo;
<a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
{% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
{% trans "Add" %} {{ opts.verbose_name }}
</div>
{% endif %}{% endblock %}
{% block content %}<div id="content-main">
<form action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
<div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
{% if save_on_top %}
<div class="submit-row" {% if is_popup %}style="overflow: auto;"{% endif %}>
<input type="submit" value="{% trans 'Submit' %}" class="default" name="_save" />
</div>
{% endif %}
{% if errors %}
<p class="errornote">
{% blocktrans count errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
</p>
{{ adminform.form.non_field_errors }}
{% endif %}
{% for fieldset in adminform %}
{% include "admin/includes/fieldset.html" %}
{% endfor %}
<div class="submit-row" {% if is_popup %}style="overflow: auto;"{% endif %}>
<input type="submit" value="{% trans 'Submit' %}" class="default" name="_save" />
</div>
<script type="text/javascript">document.getElementById("{{ adminform.first_field.id_for_label }}").focus();</script>
</div>
</form></div>
{% endblock %}
@@ -1,15 +1,12 @@
{% extends "admin/change_form.html" %}
{% load i18n polymorphic_admin_tags %}
{# fix breadcrumb #}
{% block breadcrumbs %}{% if not is_popup %}{% breadcrumb_scope base_opts %}
<div class="breadcrumbs">
<a href="../../../">{% trans "Home" %}</a> &rsaquo;
<a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
{% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
{% for p in parent_object.breadcrumb %}
<a href="../{{ p.id }}/">{{ p.title }}</a> &rsaquo;
{% endfor %}
{% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
</div>
{% endbreadcrumb_scope %}{% endif %}{% endblock %}
@@ -6,9 +6,6 @@
<a href="../../../../">{% trans "Home" %}</a> &rsaquo;
<a href="../../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
<a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
{% for p in parent_object.breadcrumb %}
<a href="../{{ p.id }}/">{{ p.title }}</a> &rsaquo;
{% endfor %}
<a href="../">{{ object|truncatewords:"18" }}</a> &rsaquo;
{% trans 'Delete' %}
</div>