Ticket #9071: add-r9017.diff
File add-r9017.diff, 2.6 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/options.py
38 38 filter_horizontal = () 39 39 radio_fields = {} 40 40 prepopulated_fields = {} 41 exclude_add = [] 41 42 42 43 def formfield_for_dbfield(self, db_field, **kwargs): 43 44 """ … … 137 138 # formfield can be None if it came from a OneToOneField with 138 139 # parent_link=True 139 140 if formfield is not None: 140 formfield.widget = widgets.RelatedFieldWidgetWrapper(formfield.widget, db_field.rel, self.admin_site) 141 add = db_field.name not in self.exclude_add 142 print formfield.widget 143 formfield.widget = widgets.RelatedFieldWidgetWrapper(formfield.widget, db_field.rel, self.admin_site, add) 141 144 return formfield 142 145 143 146 # For any other type of field, just call its formfield() method. -
django/contrib/admin/widgets.py
196 196 This class is a wrapper to a given widget to add the add icon for the 197 197 admin interface. 198 198 """ 199 def __init__(self, widget, rel, admin_site ):199 def __init__(self, widget, rel, admin_site, add=True): 200 200 self.is_hidden = widget.is_hidden 201 201 self.needs_multipart_form = widget.needs_multipart_form 202 202 self.attrs = widget.attrs 203 203 self.choices = widget.choices 204 204 self.widget = widget 205 205 self.rel = rel 206 self.add = add 206 207 # so we can check if the related object is registered with this AdminSite 207 208 self.admin_site = admin_site 208 209 … … 222 223 related_url = '../../../%s/%s/' % (rel_to._meta.app_label, rel_to._meta.object_name.lower()) 223 224 self.widget.choices = self.choices 224 225 output = [self.widget.render(name, value, *args, **kwargs)] 225 if rel_to in self.admin_site._registry: # If the related object has an admin interface: 226 # if the related object has an admin interface and we can show it 227 if self.add and rel_to in self.admin_site._registry: 226 228 # TODO: "id_" is hard-coded here. This should instead use the correct 227 229 # API to determine the ID dynamically. 228 230 output.append(u'<a href="%sadd/" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \