Ticket #9071: add-r9050.diff

File add-r9050.diff, 2.5 KB (added by Ivan Giuliani, 16 years ago)
  • django/contrib/admin/options.py

     
    3838    filter_horizontal = ()
    3939    radio_fields = {}
    4040    prepopulated_fields = {}
     41    exclude_add = []
    4142
    4243    def formfield_for_dbfield(self, db_field, **kwargs):
    4344        """
     
    137138                # formfield can be None if it came from a OneToOneField with
    138139                # parent_link=True
    139140                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                    formfield.widget = widgets.RelatedFieldWidgetWrapper(formfield.widget, db_field.rel, self.admin_site, add)
    141143            return formfield
    142144
    143145        # For any other type of field, just call its formfield() method.
  • django/contrib/admin/widgets.py

     
    196196    This class is a wrapper to a given widget to add the add icon for the
    197197    admin interface.
    198198    """
    199     def __init__(self, widget, rel, admin_site):
     199    def __init__(self, widget, rel, admin_site, add=True):
    200200        self.is_hidden = widget.is_hidden
    201201        self.needs_multipart_form = widget.needs_multipart_form
    202202        self.attrs = widget.attrs
    203203        self.choices = widget.choices
    204204        self.widget = widget
    205205        self.rel = rel
     206        self.add = add
    206207        # so we can check if the related object is registered with this AdminSite
    207208        self.admin_site = admin_site
    208209
     
    222223        related_url = '../../../%s/%s/' % (rel_to._meta.app_label, rel_to._meta.object_name.lower())
    223224        self.widget.choices = self.choices
    224225        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:
    226228            # TODO: "id_" is hard-coded here. This should instead use the correct
    227229            # API to determine the ID dynamically.
    228230            output.append(u'<a href="%sadd/" class="add-another" id="add_id_%s" onclick="return showAddAnotherPopup(this);"> ' % \
Back to Top