Ticket #4491: newforms-admin-5427-site_to_admin_opts.diff
File newforms-admin-5427-site_to_admin_opts.diff, 3.2 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/options.py
114 114 filter_vertical = () 115 115 filter_horizontal = () 116 116 117 def __init__(self, model ):117 def __init__(self, model, site): 118 118 self.model = model 119 119 self.opts = model._meta 120 self.site = site 120 121 121 122 def __call__(self, request, url): 122 123 # Check that LogEntry, ContentType and the auth context processor are installed. … … 238 239 # Wrap the widget's render() method with a method that adds 239 240 # extra HTML to the end of the rendered output. 240 241 formfield = db_field.formfield(**kwargs) 241 formfield.widget.render = widgets.RelatedFieldWidgetWrapper(formfield.widget.render, db_field.rel )242 formfield.widget.render = widgets.RelatedFieldWidgetWrapper(formfield.widget.render, db_field.rel, self.site) 242 243 return formfield 243 244 244 245 # For any other type of field, just call its formfield() method. -
django/contrib/admin/widgets.py
74 74 This class is a wrapper whose __call__() method mimics the interface of a 75 75 Widget's render() method. 76 76 """ 77 def __init__(self, render_func, rel ):78 self.render_func, self.rel = render_func, rel77 def __init__(self, render_func, rel, site): 78 self.render_func, self.rel, self.site = render_func, rel, site 79 79 80 80 def __call__(self, name, value, *args, **kwargs): 81 81 from django.conf import settings 82 82 rel_to = self.rel.to 83 83 related_url = '../../../%s/%s/' % (rel_to._meta.app_label, rel_to._meta.object_name.lower()) 84 84 output = [self.render_func(name, value, *args, **kwargs)] 85 if rel_to ._meta.admin: # If the related object has an admin interface:85 if rel_to in self.site._registry: # If the related object has an admin interface: 86 86 # TODO: "id_" is hard-coded here. This should instead use the correct 87 87 # API to determine the ID dynamically. 88 output 88 89 output.append(u'<a href="%sadd/" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \ 89 90 (related_url, name)) 90 91 output.append(u'<img src="%simg/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a>' % settings.ADMIN_MEDIA_PREFIX) -
django/contrib/admin/sites.py
74 75 for model in model_or_iterable: 75 76 if model in self._registry: 76 77 raise AlreadyRegistered('The model %s is already registered' % model.__class__.__name__) 77 self._registry[model] = admin_class(model )78 self._registry[model] = admin_class(model, self) 78 79 79 80 def unregister(self, model_or_iterable): 80 81 """