Ticket #17547: django-baseadmin-addlink-optional.patch

File django-baseadmin-addlink-optional.patch, 1.2 KB (added by Chris Wilson, 13 years ago)

patch to add this feature

  • contrib/admin/options.py

     
    7878        overrides.update(self.formfield_overrides)
    7979        self.formfield_overrides = overrides
    8080
    81     def formfield_for_dbfield(self, db_field, **kwargs):
     81    def formfield_for_dbfield(self, db_field, can_add_related=True, **kwargs):
    8282        """
    8383        Hook for specifying the form Field instance for a given database Field
    8484        instance.
     
    111111            # extra HTML -- the "add other" interface -- to the end of the
    112112            # rendered output. formfield can be None if it came from a
    113113            # OneToOneField with parent_link=True or a M2M intermediary.
    114             if formfield and db_field.name not in self.raw_id_fields:
     114            if (can_add_related and formfield and
     115                db_field.name not in self.raw_id_fields):
    115116                related_modeladmin = self.admin_site._registry.get(
    116117                                                            db_field.rel.to)
    117118                can_add_related = bool(related_modeladmin and
Back to Top