update third-party docs for better reversion support

also mention mptt options
fix_request_path_info
Diederik van der Boor 2016-02-17 11:13:40 +01:00
parent efdebb1575
commit f2c323754b
1 changed files with 47 additions and 14 deletions

View File

@ -1,23 +1,21 @@
Third-party applications support Third-party applications support
================================ ================================
Django-reversion support django-reversion support
------------------------ ------------------------
`Django-reversion <https://github.com/etianen/django-reversion>`_ works as Support for django-reversion_ works as expected with polymorphic models.
expected with polymorphic models. However, they require more setup than However, they require more setup than standard models. That's become:
standard models. We have to face these problems:
* The children models are not registered in the admin site. * The children models are not registered in the admin site.
You will therefore need to manually register them to django-reversion. You will therefore need to manually register them to django-reversion_.
* Polymorphic models use * Polymorphic models use `multi-table inheritance <https://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-inheritance>`_.
`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>`_
The django-reversion wiki explains how to deal with this by adding a ``follow`` field for the primary key.
`how to deal with this <https://github.com/etianen/django-reversion/wiki/Low-level-API#multi-table-inheritance>`_.
Example Example
....... ~~~~~~~
The admin :ref:`admin-example` becomes: The admin :ref:`admin-example` becomes:
@ -25,8 +23,8 @@ The admin :ref:`admin-example` becomes:
from django.contrib import admin from django.contrib import admin
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin
import reversion from reversion.admin import VersionAdmin
from reversion import VersionAdmin from reversion import revisions
from .models import ModelA, ModelB, ModelC from .models import ModelA, ModelB, ModelC
@ -51,6 +49,41 @@ The admin :ref:`admin-example` becomes:
(ModelC, ModelCAdmin), (ModelC, ModelCAdmin),
) )
reversion.register(ModelB, follow=['modela_ptr']) revisions.register(ModelB, follow=['modela_ptr'])
reversion.register(ModelC, follow=['modelb_ptr']) revisions.register(ModelC, follow=['modelb_ptr'])
admin.site.register(ModelA, ModelAParentAdmin) admin.site.register(ModelA, ModelAParentAdmin)
.. _django-reversion-compare-support:
django-reversion-compare support
--------------------------------
The django-reversion-compare_ views work as expected, the admin requires a little tweak.
In your parent admin, include the following method:
.. code-block:: python
def compare_view(self, request, object_id, extra_context=None):
"""Redirect the reversion-compare view to the child admin."""
real_admin = self._get_real_admin(object_id)
return real_admin.compare_view(request, object_id, extra_context=extra_context)
As the compare view resolves the the parent admin, it uses it's base model to find revisions.
This doesn't work, since it needs to look for revisions of the child model. Using this tweak,
the view of the actual child model is used, similar to the way the regular change and delete views are redirected.
django-mptt support
-------------------
Combining polymorphic with django-mptt_ is certainly possible, but not straightforward.
It involves combining both managers, querysets, models, meta-classes and admin classes
using multiple inheritance.
The django-polymorphic-tree_ package provides this out of the box.
.. _django-reversion: https://github.com/etianen/django-reversion
.. _django-reversion-compare: https://github.com/jedie/django-reversion-compare
.. _django-mptt: https://github.com/django-mptt/django-mptt
.. _django-polymorphic-tree: https://github.com/edoburu/django-polymorphic-tree