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.fix_request_path_info
parent
88bb23b506
commit
ccda52d91e
|
|
@ -8,6 +8,10 @@ Changes in git
|
||||||
* Fixed Django 1.7 ``changeform_view()`` redirection to the child admin site.
|
* 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()``.
|
This fixes custom admin code that uses these views, such as django-reversion_'s ``revision_view()`` / ``recover_view()``.
|
||||||
* Fixed ``.only('pk')`` field support.
|
* 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)
|
Version 0.9 (2016-02-17)
|
||||||
|
|
|
||||||
|
|
@ -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>`_.
|
* 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>`_
|
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.
|
how to deal with this by adding a ``follow`` field for the primary key.
|
||||||
|
* Both admin classes redefine ``object_history_template``.
|
||||||
|
|
||||||
|
|
||||||
Example
|
Example
|
||||||
|
|
@ -28,14 +29,14 @@ The admin :ref:`admin-example` becomes:
|
||||||
from .models import ModelA, ModelB, ModelC
|
from .models import ModelA, ModelB, ModelC
|
||||||
|
|
||||||
|
|
||||||
class ModelAChildAdmin(PolymorphicChildModelAdmin):
|
class ModelAChildAdmin(PolymorphicChildModelAdmin, VersionAdmin):
|
||||||
base_model = ModelA
|
base_model = ModelA
|
||||||
base_form = ...
|
base_form = ...
|
||||||
base_fieldsets = (
|
base_fieldsets = (
|
||||||
...
|
...
|
||||||
)
|
)
|
||||||
|
|
||||||
class ModelBAdmin(VersionAdmin, ModelAChildAdmin):
|
class ModelBAdmin(ModelAChildAdmin, VersionAdmin):
|
||||||
# define custom features here
|
# define custom features here
|
||||||
|
|
||||||
class ModelCAdmin(ModelBAdmin):
|
class ModelCAdmin(ModelBAdmin):
|
||||||
|
|
@ -53,6 +54,19 @@ The admin :ref:`admin-example` becomes:
|
||||||
revisions.register(ModelC, follow=['modelb_ptr'])
|
revisions.register(ModelC, follow=['modelb_ptr'])
|
||||||
admin.site.register(ModelA, ModelAParentAdmin)
|
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:
|
||||||
|
|
||||||
django-reversion-compare support
|
django-reversion-compare support
|
||||||
|
|
|
||||||
|
|
@ -525,6 +525,25 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
|
||||||
"admin/delete_confirmation.html"
|
"admin/delete_confirmation.html"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def object_history_template(self):
|
||||||
|
opts = self.model._meta
|
||||||
|
app_label = opts.app_label
|
||||||
|
|
||||||
|
# Pass the base options
|
||||||
|
base_opts = self.base_model._meta
|
||||||
|
base_app_label = base_opts.app_label
|
||||||
|
|
||||||
|
return [
|
||||||
|
"admin/%s/%s/object_history.html" % (app_label, opts.object_name.lower()),
|
||||||
|
"admin/%s/object_history.html" % app_label,
|
||||||
|
# Added:
|
||||||
|
"admin/%s/%s/object_history.html" % (base_app_label, base_opts.object_name.lower()),
|
||||||
|
"admin/%s/object_history.html" % base_app_label,
|
||||||
|
"admin/polymorphic/object_history.html",
|
||||||
|
"admin/object_history.html"
|
||||||
|
]
|
||||||
|
|
||||||
def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
|
def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
|
||||||
context.update({
|
context.update({
|
||||||
'base_opts': self.base_model._meta,
|
'base_opts': self.base_model._meta,
|
||||||
|
|
@ -537,6 +556,16 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
|
||||||
}
|
}
|
||||||
return super(PolymorphicChildModelAdmin, self).delete_view(request, object_id, extra_context)
|
return super(PolymorphicChildModelAdmin, self).delete_view(request, object_id, extra_context)
|
||||||
|
|
||||||
|
def history_view(self, request, object_id, extra_context=None):
|
||||||
|
# Make sure the history view can also display polymorphic breadcrumbs
|
||||||
|
context = {
|
||||||
|
'base_opts': self.base_model._meta,
|
||||||
|
}
|
||||||
|
if extra_context:
|
||||||
|
context.update(extra_context)
|
||||||
|
return super(PolymorphicChildModelAdmin, self).history_view(request, object_id, extra_context=context)
|
||||||
|
|
||||||
|
|
||||||
# ---- Extra: improving the form/fieldset default display ----
|
# ---- Extra: improving the form/fieldset default display ----
|
||||||
|
|
||||||
def get_fieldsets(self, request, obj=None):
|
def get_fieldsets(self, request, obj=None):
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
{% extends "admin/object_history.html" %}
|
||||||
|
{% load polymorphic_admin_tags %}
|
||||||
|
|
||||||
|
{% block breadcrumbs %}
|
||||||
|
{% breadcrumb_scope base_opts %}{{ block.super }}{% endbreadcrumb_scope %}
|
||||||
|
{% endblock %}
|
||||||
Loading…
Reference in New Issue