Skip to content
Browse files

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

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 4ccc5ff commit c05527dd609c26e4788df7eebb003c82033199e7 @jkocherhans jkocherhans committed
Showing with 5 additions and 3 deletions.
  1. +1 −1 django/contrib/admin/
  2. +4 −2 django/contrib/admin/
2 django/contrib/admin/
@@ -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.
6 django/contrib/admin/
@@ -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 =
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);"> ' % \

0 comments on commit c05527d

Please sign in to comment.
Something went wrong with that request. Please try again.