From 53d16b1175682f1ff97358b67190e4c935372b26 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 23 Jul 2009 14:31:33 +0000 Subject: [PATCH] Fixed #11532 -- Corrected the link used for edit_inline foreign keys in admin when the admin is deployed using the old style admin.root approach. Thanks to JP for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11314 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/widgets.py | 3 ++- tests/regressiontests/admin_widgets/tests.py | 9 +++++++-- tests/regressiontests/admin_widgets/urls2.py | 7 +++++++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 tests/regressiontests/admin_widgets/urls2.py diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 1a081bc293..eacea44a31 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -224,7 +224,8 @@ class RelatedFieldWidgetWrapper(forms.Widget): try: related_url = reverse('admin:%s_%s_add' % info, current_app=self.admin_site.name) except NoReverseMatch: - related_url = '../../../%s/%s/add/' % info + info = (self.admin_site.root_path, rel_to._meta.app_label, rel_to._meta.object_name.lower()) + related_url = '%s%s/%s/add/' % info self.widget.choices = self.choices output = [self.widget.render(name, value, *args, **kwargs)] if rel_to in self.admin_site._registry: # If the related object has an admin interface: diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py index 55088ca1fe..85651542bb 100644 --- a/tests/regressiontests/admin_widgets/tests.py +++ b/tests/regressiontests/admin_widgets/tests.py @@ -115,6 +115,7 @@ class AdminFormfieldForDBFieldWithRequestTests(DjangoTestCase): class AdminForeignKeyWidgetChangeList(DjangoTestCase): fixtures = ["admin-widgets-users.xml"] + admin_root = '/widget_admin' def setUp(self): self.client.login(username="super", password="secret") @@ -123,5 +124,9 @@ class AdminForeignKeyWidgetChangeList(DjangoTestCase): self.client.logout() def test_changelist_foreignkey(self): - response = self.client.get('/widget_admin/admin_widgets/car/') - self.failUnless('/widget_admin/auth/user/add/' in response.content) + response = self.client.get('%s/admin_widgets/car/' % self.admin_root) + self.failUnless('%s/auth/user/add/' % self.admin_root in response.content) + +class OldAdminForeignKeyWidgetChangeList(AdminForeignKeyWidgetChangeList): + urls = 'regressiontests.admin_widgets.urls2' + admin_root = '/deep/down/admin' diff --git a/tests/regressiontests/admin_widgets/urls2.py b/tests/regressiontests/admin_widgets/urls2.py new file mode 100644 index 0000000000..1ad060cd09 --- /dev/null +++ b/tests/regressiontests/admin_widgets/urls2.py @@ -0,0 +1,7 @@ + +from django.conf.urls.defaults import * +import widgetadmin + +urlpatterns = patterns('', + (r'^deep/down/admin/(.*)', widgetadmin.site.root), +)