Skip to content

Instantly share code, notes, and snippets.

@cheldernunes
Created October 5, 2018 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheldernunes/95a6460c376cde211839bab8b0983e18 to your computer and use it in GitHub Desktop.
Save cheldernunes/95a6460c376cde211839bab8b0983e18 to your computer and use it in GitHub Desktop.
This gist show how remove add link in related fields in admin django. Replace field_name with your field.
@admin.register(ModelName)
class CustomAdmin(admin.ModelAdmin):
def formfield_for_dbfield(self, db_field, **kwargs):
formfield = super().formfield_for_dbfield(db_field, **kwargs)
if db_field.name == "field_name":
formfield.widget.can_add_related = False
return formfield
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment