summaryrefslogtreecommitdiff
path: root/django/contrib/admin/widgets.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-07-16 16:16:13 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-07-16 16:16:13 +0000
commit8d48eaa064c88533be5082e3f45638fbd48491d8 (patch)
tree869920eb92a7e4b4248b3adf5e3f9104c4d57532 /django/contrib/admin/widgets.py
parent9fd19c01611e5ed1ed64bbeb462ab96499d72a6c (diff)
Fixed #10061 -- Added namespacing for named URLs - most importantly, for the admin site, where the absence of this facility was causing problems. Thanks to the many people who contributed to and helped review this patch.
This change is backwards incompatible for anyone that is using the named URLs introduced in [9739]. Any usage of the old admin_XXX names need to be modified to use the new namespaced format; in many cases this will be as simple as a search & replace for "admin_" -> "admin:". See the docs for more details on the new URL names, and the namespace resolution strategy. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11250 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib/admin/widgets.py')
-rw-r--r--django/contrib/admin/widgets.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index 7ae5e647db..1a081bc293 100644
--- a/django/contrib/admin/widgets.py
+++ b/django/contrib/admin/widgets.py
@@ -125,7 +125,7 @@ class ForeignKeyRawIdWidget(forms.TextInput):
if value:
output.append(self.label_for_value(value))
return mark_safe(u''.join(output))
-
+
def base_url_parameters(self):
params = {}
if self.rel.limit_choices_to:
@@ -137,14 +137,14 @@ class ForeignKeyRawIdWidget(forms.TextInput):
v = str(v)
items.append((k, v))
params.update(dict(items))
- return params
-
+ return params
+
def url_parameters(self):
from django.contrib.admin.views.main import TO_FIELD_VAR
params = self.base_url_parameters()
params.update({TO_FIELD_VAR: self.rel.get_related_field().name})
return params
-
+
def label_for_value(self, value):
key = self.rel.get_related_field().name
obj = self.rel.to._default_manager.get(**{key: value})
@@ -165,10 +165,10 @@ class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
else:
value = ''
return super(ManyToManyRawIdWidget, self).render(name, value, attrs)
-
+
def url_parameters(self):
return self.base_url_parameters()
-
+
def label_for_value(self, value):
return ''
@@ -222,8 +222,7 @@ class RelatedFieldWidgetWrapper(forms.Widget):
rel_to = self.rel.to
info = (rel_to._meta.app_label, rel_to._meta.object_name.lower())
try:
- related_info = (self.admin_site.name,) + info
- related_url = reverse('%sadmin_%s_%s_add' % related_info)
+ related_url = reverse('admin:%s_%s_add' % info, current_app=self.admin_site.name)
except NoReverseMatch:
related_url = '../../../%s/%s/add/' % info
self.widget.choices = self.choices