The Django Web Framework makes it quite easy to add new referenced objects in the admin menu.
Let’s say the model has two foreign keys in it:
And the admin form:
Then Django will show small a small green
+ sign next to the fields:
However that is not always desirable. In my use case I want a clear separation between changing teams, and changing team members. Note: this can’t be resolved with permissions (removing the permissions for one one model will remove the
add option, but that’s not what I want - I still want permissions for both, just separate the actions).
Django makes it easy to remove the option to add new references inline in this form. In order to do that, the
ModelAdmin must be extended by a
In this function, the widgets for the two fields have an extra
can_add_related option set to
False. That is enough to disable this option.
By the way: the same way the
add new reference option can be disabled, it is also possible to disable the
widget.can_change_relatedwill disable the
widget.can_delete_relatedwill disable the