From e73a4662c3ded88c39ac49b73200a8858ed7b43c Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Fri, 23 Oct 2015 19:55:45 -0300 Subject: [PATCH] Prevent infinite redirection on django1.9 See here[1] as to why this is an issue, and why we can skip the avoided code on django>=1.9. [1]: https://docs.djangoproject.com/en/1.9/releases/1.9/#django-contrib-admin --- polymorphic/admin.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/polymorphic/admin.py b/polymorphic/admin.py index 3b99ab8..d80e484 100644 --- a/polymorphic/admin.py +++ b/polymorphic/admin.py @@ -18,6 +18,7 @@ from django.utils.encoding import force_text from django.utils.http import urlencode from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ +import django try: @@ -298,10 +299,16 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin): # Patch the change URL so it's not a big catch-all; allowing all custom URLs to be added to the end. # The url needs to be recreated, patching url.regex is not an option Django 1.4's LocaleRegexProvider changed it. - new_change_url = url(r'^{0}/$'.format(self.pk_regex), self.admin_site.admin_view(self.change_view), name='{0}_{1}_change'.format(*info)) - for i, oldurl in enumerate(urls): - if oldurl.name == new_change_url.name: - urls[i] = new_change_url + if django.VERSION < (1, 9): + new_change_url = url( + r'^{0}/$'.format(self.pk_regex), + self.admin_site.admin_view(self.change_view), + name='{0}_{1}_change'.format(*info) + ) + + for i, oldurl in enumerate(urls): + if oldurl.name == new_change_url.name: + urls[i] = new_change_url # Define the catch-all for custom views custom_urls = [