Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

newforms-admin: Fixed #4491. Thanks Honza Kral.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6074 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c05527dd609c26e4788df7eebb003c82033199e7 1 parent 4ccc5ff
@jkocherhans jkocherhans authored
View
2  django/contrib/admin/options.py
@@ -157,7 +157,7 @@ def formfield_for_dbfield(self, db_field, **kwargs):
# Wrap the widget's render() method with a method that adds
# extra HTML to the end of the rendered output.
formfield = db_field.formfield(**kwargs)
- formfield.widget.render = widgets.RelatedFieldWidgetWrapper(formfield.widget.render, db_field.rel)
+ formfield.widget.render = widgets.RelatedFieldWidgetWrapper(formfield.widget.render, db_field.rel, self.admin_site)
return formfield
# For any other type of field, just call its formfield() method.
View
6 django/contrib/admin/widgets.py
@@ -91,15 +91,17 @@ class RelatedFieldWidgetWrapper(object):
This class is a wrapper whose __call__() method mimics the interface of a
Widget's render() method.
"""
- def __init__(self, render_func, rel):
+ def __init__(self, render_func, rel, admin_site):
self.render_func, self.rel = render_func, rel
+ # so we can check if the related object is registered with this AdminSite
+ self.admin_site = admin_site
def __call__(self, name, value, *args, **kwargs):
from django.conf import settings
rel_to = self.rel.to
related_url = '../../../%s/%s/' % (rel_to._meta.app_label, rel_to._meta.object_name.lower())
output = [self.render_func(name, value, *args, **kwargs)]
- if rel_to._meta.admin: # If the related object has an admin interface:
+ if rel_to in self.admin_site._registry: # If the related object has an admin interface:
# TODO: "id_" is hard-coded here. This should instead use the correct
# API to determine the ID dynamically.
output.append(u'<a href="%sadd/" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \
Please sign in to comment.
Something went wrong with that request. Please try again.