Fix changeform_view() redirection to the child admin site.
This method is normally called from `add_view()` and `change_view()`. However, some third party modules (such as django-reversion) call this method directly. By redirecting those calls to the child admin, their views also display the proper admin views.fix_request_path_info
parent
65de1f74ab
commit
46e41a6c1c
|
|
@ -1,6 +1,14 @@
|
||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
Changes in git
|
||||||
|
--------------
|
||||||
|
|
||||||
|
* Fixed support for ``PolymorphicManager.from_queryset()`` for custom query sets.
|
||||||
|
* 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()``.
|
||||||
|
|
||||||
|
|
||||||
Version 0.9 (2016-02-17)
|
Version 0.9 (2016-02-17)
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
|
@ -9,7 +17,7 @@ Version 0.9 (2016-02-17)
|
||||||
* Fix Django 1.9 handling of custom URLs.
|
* Fix Django 1.9 handling of custom URLs.
|
||||||
The new change-URL redirect overlapped any custom URLs defined in the child admin.
|
The new change-URL redirect overlapped any custom URLs defined in the child admin.
|
||||||
* Fix Django 1.9 support in the admin.
|
* Fix Django 1.9 support in the admin.
|
||||||
* Fix missing ``history_view`` redirection to the child admin, which is important for django-reversion_ support.
|
* Fix missing ``history_view()`` redirection to the child admin, which is important for django-reversion_ support.
|
||||||
See the documentation for hints for :ref:`django-reversion-compare support <django-reversion-compare-support>`.
|
See the documentation for hints for :ref:`django-reversion-compare support <django-reversion-compare-support>`.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -262,6 +262,18 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||||
real_admin = self._get_real_admin(object_id)
|
real_admin = self._get_real_admin(object_id)
|
||||||
return real_admin.change_view(request, object_id, *args, **kwargs)
|
return real_admin.change_view(request, object_id, *args, **kwargs)
|
||||||
|
|
||||||
|
if django.VERSION >= (1, 7):
|
||||||
|
def changeform_view(self, request, object_id=None, *args, **kwargs):
|
||||||
|
# The `changeform_view` is available as of Django 1.7, combining the add_view and change_view.
|
||||||
|
# As it's directly called by django-reversion, this method is also overwritten to make sure it
|
||||||
|
# also redirects to the child admin.
|
||||||
|
if object_id:
|
||||||
|
real_admin = self._get_real_admin(object_id)
|
||||||
|
return real_admin.changeform_view(request, object_id, *args, **kwargs)
|
||||||
|
else:
|
||||||
|
# Add view. As it should already be handled via `add_view`, this means something custom is done here!
|
||||||
|
return super(PolymorphicParentModelAdmin, self).changeform_view(request, object_id, *args, **kwargs)
|
||||||
|
|
||||||
def history_view(self, request, object_id, extra_context=None):
|
def history_view(self, request, object_id, extra_context=None):
|
||||||
"""Redirect the history view to the real admin."""
|
"""Redirect the history view to the real admin."""
|
||||||
real_admin = self._get_real_admin(object_id)
|
real_admin = self._get_real_admin(object_id)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue