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:
@@ -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> ›
|
||||
<a href="../../">{{ app_label|capfirst|escape }}</a> ›
|
||||
{% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} ›
|
||||
{% for p in parent_object.breadcrumb %}
|
||||
<a href="../{{ p.id }}/">{{ p.title }}</a> ›
|
||||
{% 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> ›
|
||||
<a href="../../../">{{ app_label|capfirst|escape }}</a> ›
|
||||
<a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> ›
|
||||
{% for p in parent_object.breadcrumb %}
|
||||
<a href="../{{ p.id }}/">{{ p.title }}</a> ›
|
||||
{% endfor %}
|
||||
<a href="../">{{ object|truncatewords:"18" }}</a> ›
|
||||
{% trans 'Delete' %}
|
||||
</div>
|
||||
{% endbreadcrumb_scope %}{% endblock %}
|
||||
Reference in New Issue
Block a user