Added polymorphic admin interface

Extracted from django-fluent-pages, ready for other apps too.
The polymorphic admin is implemented via a parent admin for the base
model, and separate admin interfaces for the child models.

The parent model needs to inherit PolymorphicParentModelAdmin,
and override `get_admin_for_model()` and `get_child_model_classes()`
to find the child admin interfaces.

The derived models have their own `ModelAdmin` class, which inherits
from `PolymorphicChildModelAdmin`. The parent admin redirects it's
change and delete views to the child admin.

By adding `polymorphic` to the INSTALLED_APPS, the breadcrumbs will be
fixed as well, to remain unchanged between the child applications.
This commit is contained in:
Diederik van der Boor
2012-07-05 22:12:01 +02:00
parent db4cc4dc3b
commit 5d65bf4bbc
8 changed files with 551 additions and 0 deletions
@@ -0,0 +1,15 @@
{% extends "admin/change_form.html" %}
{% load i18n polymorphic_admin_tags %}
{% 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 %}
@@ -0,0 +1,15 @@
{% extends "admin/delete_confirmation.html" %}
{% load i18n polymorphic_admin_tags %}
{% block breadcrumbs %}{% breadcrumb_scope base_opts %}
<div class="breadcrumbs">
<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>
{% endbreadcrumb_scope %}{% endblock %}