Fixed the breadcrumb of the object_history template.

NOTE: this could conflict with projects that use django-reversion,
if the `VersionAdmin` is the last in the inheritance chain.
This commit is contained in:
Diederik van der Boor
2016-02-18 18:17:08 +01:00
parent 88bb23b506
commit ccda52d91e
4 changed files with 55 additions and 2 deletions
+4
View File
@@ -8,6 +8,10 @@ Changes in git
* Fixed Django 1.7 ``changeform_view()`` redirection to the child admin site.
This fixes custom admin code that uses these views, such as django-reversion_'s ``revision_view()`` / ``recover_view()``.
* Fixed ``.only('pk')`` field support.
* Fixed ``object_history_template`` breadcrumb.
**NOTE:** when using django-reversion_ / django-reversion-compare_, make sure to implement
a ``admin/polymorphic/object_history.html`` template in your project that extends
from ``reversion/object_history.html`` or ``reversion-compare/object_history.html`` respectively.
Version 0.9 (2016-02-17)
+16 -2
View File
@@ -12,6 +12,7 @@ However, they require more setup than standard models. That's become:
* Polymorphic models use `multi-table inheritance <https://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-inheritance>`_.
See the `reversion documentation <http://django-reversion.readthedocs.org/en/latest/api.html#multi-table-inheritance>`_
how to deal with this by adding a ``follow`` field for the primary key.
* Both admin classes redefine ``object_history_template``.
Example
@@ -28,14 +29,14 @@ The admin :ref:`admin-example` becomes:
from .models import ModelA, ModelB, ModelC
class ModelAChildAdmin(PolymorphicChildModelAdmin):
class ModelAChildAdmin(PolymorphicChildModelAdmin, VersionAdmin):
base_model = ModelA
base_form = ...
base_fieldsets = (
...
)
class ModelBAdmin(VersionAdmin, ModelAChildAdmin):
class ModelBAdmin(ModelAChildAdmin, VersionAdmin):
# define custom features here
class ModelCAdmin(ModelBAdmin):
@@ -53,6 +54,19 @@ The admin :ref:`admin-example` becomes:
revisions.register(ModelC, follow=['modelb_ptr'])
admin.site.register(ModelA, ModelAParentAdmin)
Redefine a :file:`admin/polymorphic/object_history.html` template, so it combines both worlds:
.. code-block:: html+django
{% extends 'reversion/object_history.html' %}
{% load polymorphic_admin_tags %}
{% block breadcrumbs %}
{% breadcrumb_scope base_opts %}{{ block.super }}{% endbreadcrumb_scope %}
{% endblock %}
This makes sure both the reversion template is used, and the breadcrumb is corrected for the polymorphic model.
.. _django-reversion-compare-support:
django-reversion-compare support