Ticket #4491: newforms-admin-5519-site_to_admin_opts.diff
File newforms-admin-5519-site_to_admin_opts.diff, 3.0 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/sites.py
74 74 for model in model_or_iterable: 75 75 if model in self._registry: 76 76 raise AlreadyRegistered('The model %s is already registered' % model.__class__.__name__) 77 self._registry[model] = admin_class(model )77 self._registry[model] = admin_class(model, self) 78 78 79 79 def unregister(self, model_or_iterable): 80 80 """ -
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 88 output.append(u'<a href="%sadd/" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \ -
django/contrib/admin/options.py
138 138 # Wrap the widget's render() method with a method that adds 139 139 # extra HTML to the end of the rendered output. 140 140 formfield = db_field.formfield(**kwargs) 141 formfield.widget.render = widgets.RelatedFieldWidgetWrapper(formfield.widget.render, db_field.rel )141 formfield.widget.render = widgets.RelatedFieldWidgetWrapper(formfield.widget.render, db_field.rel, self.site) 142 142 return formfield 143 143 144 144 # For any other type of field, just call its formfield() method. … … 163 163 filter_horizontal = () 164 164 inlines = [] 165 165 166 def __init__(self, model ):166 def __init__(self, model, site): 167 167 self.model = model 168 168 self.opts = model._meta 169 self.site = site 169 170 170 171 def __call__(self, request, url): 171 172 # Check that LogEntry, ContentType and the auth context processor are installed.