#17547: How to suppress icon_addlink.gif (RelatedFieldWidgetWrapper) in admin interfaces -------------------------------+-------------------- Reporter: gcc | Owner: nobody Type: New feature | Status: new Component: contrib.admin | Version: 1.3 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 1 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------- BaseModelAdmin's formfield_for_dbfield() method always wraps relations to other tables (ForeignKey and ManyToManyField) in a RelatedFieldWidgetWrapper, which renders a green Add button next to the field.
You might not want to show this to users, if you're building your interface on top of the admin interface to get automatic CRUD operations. However it's difficult to prevent: {{{ def formfield_for_dbfield(self, db_field, **kwargs): ... if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)): ... # For non-raw_id fields, wrap the widget with a wrapper that adds # extra HTML -- the "add other" interface -- to the end of the # rendered output. formfield can be None if it came from a # OneToOneField with parent_link=True or a M2M intermediary. if formfield and db_field.name not in self.raw_id_fields: related_modeladmin = self.admin_site._registry.get( db_field.rel.to) can_add_related = bool(related_modeladmin and related_modeladmin.has_add_permission(request)) formfield.widget = widgets.RelatedFieldWidgetWrapper( formfield.widget, db_field.rel, self.admin_site, can_add_related=can_add_related) return formfield }}} I worked around this by overriding `formfield_for_dbfield` to undo the wrapping: {{{ class DocumentAdmin(admin.ModelAdmin): def formfield_for_dbfield(self, db_field, **kwargs): old_formfield = admin.ModelAdmin.formfield_for_dbfield(self, db_field, **kwargs) if (hasattr(old_formfield, 'widget') and isinstance(old_formfield.widget, RelatedFieldWidgetWrapper)): old_formfield.widget.can_add_related = False return old_formfield }}} However it would be nice to have a keyword argument to disable this behaviour. -- Ticket URL: <https://code.djangoproject.com/ticket/17547> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.