Ticket #6202: 6202.diff
File 6202.diff, 2.5 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/options.py
147 147 """ 148 148 # For ManyToManyFields with a filter interface, use a special widget. 149 149 if isinstance(db_field, models.ManyToManyField) and db_field.name in (self.filter_vertical + self.filter_horizontal): 150 kwargs['widget'] = widgets.FilteredSelectMultiple(db_field.verbose_name, (db_field.name in self.filter_vertical)) 150 # If related model has an admin interface, allow for add another popup 151 rel_to = db_field.rel.to in self.admin_site._registry and db_field.rel.to or None 152 kwargs['widget'] = widgets.FilteredSelectMultiple(db_field.verbose_name, (db_field.name in self.filter_vertical), rel_to=rel_to) 151 153 return db_field.formfield(**kwargs) 152 154 153 155 # For DateTimeFields, use a special field and widget. -
django/contrib/admin/widgets.py
16 16 Note that the resulting JavaScript assumes that the SelectFilter2.js 17 17 library and its dependencies have been loaded in the HTML page. 18 18 """ 19 def __init__(self, verbose_name, is_stacked, attrs=None, choices=() ):19 def __init__(self, verbose_name, is_stacked, attrs=None, choices=(), rel_to=None): 20 20 self.verbose_name = verbose_name 21 21 self.is_stacked = is_stacked 22 self.rel_to = rel_to 22 23 super(FilteredSelectMultiple, self).__init__(attrs, choices) 23 24 24 25 def render(self, name, value, attrs=None, choices=()): … … 29 30 # API to determine the ID dynamically. 30 31 output.append(u'SelectFilter.init("id_%s", "%s", %s, "%s"); });</script>\n' % \ 31 32 (name, self.verbose_name.replace('"', '\\"'), int(self.is_stacked), settings.ADMIN_MEDIA_PREFIX)) 33 if self.rel_to: 34 related_url = '../../../%s/%s/' % (self.rel_to._meta.app_label, self.rel_to._meta.object_name.lower()) 35 output.append(u'<a href="%sadd/" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \ 36 (related_url, name)) 37 output.append(u'<img src="%simg/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a>' % settings.ADMIN_MEDIA_PREFIX) 32 38 return mark_safe(u''.join(output)) 33 39 34 40 class AdminDateWidget(forms.TextInput):