Created
October 5, 2018 18:58
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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