Fix Django 1.9 handling of custom URLs.

The new change-URL redirect overlapped any custom URLs defined in the child admin.
This makes sure the redirect doesn't interfere with custom URLs.
fix_request_path_info
Diederik van der Boor 2016-02-17 11:06:03 +01:00
parent 4277c148aa
commit 01a35cfe95
1 changed files with 7 additions and 1 deletions

View File

@ -298,9 +298,15 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
name='{0}_{1}_change'.format(*info) name='{0}_{1}_change'.format(*info)
) )
redirect_urls = []
for i, oldurl in enumerate(urls): for i, oldurl in enumerate(urls):
if oldurl.name == new_change_url.name: if oldurl.name == new_change_url.name:
urls[i] = new_change_url urls[i] = new_change_url
else:
# For Django 1.9, the redirect at the end acts as catch all.
# The custom urls need to be inserted before that.
redirect_urls = [pat for pat in urls if not pat.name] # redirect URL has no name.
urls = [pat for pat in urls if pat.name]
# Define the catch-all for custom views # Define the catch-all for custom views
custom_urls = [ custom_urls = [
@ -317,7 +323,7 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
admin = self._get_real_admin_by_model(model) admin = self._get_real_admin_by_model(model)
dummy_urls += admin.get_urls() dummy_urls += admin.get_urls()
return urls + custom_urls + dummy_urls return urls + custom_urls + dummy_urls + redirect_urls
def subclass_view(self, request, path): def subclass_view(self, request, path):
""" """