From d8d6f07f71d066f1c85f32b0aaa6c83193335b1f Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 8 Jul 2014 18:05:04 +0300 Subject: [PATCH] Adds pk_regex attr in PolymorphicParentModelAdmin --- polymorphic/admin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/polymorphic/admin.py b/polymorphic/admin.py index 959e899..ac5a817 100644 --- a/polymorphic/admin.py +++ b/polymorphic/admin.py @@ -102,6 +102,8 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin): add_type_template = None add_type_form = PolymorphicModelChoiceForm + + pk_regex = '(\d+)' def __init__(self, model, admin_site, *args, **kwargs): @@ -247,7 +249,7 @@ 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'^(\d+)/$', self.admin_site.admin_view(self.change_view), name='{0}_{1}_change'.format(*info)) + 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