2👍
The answer lies in the code of the BaseModelAdmin class and the RelatedFieldWidgetWrapper class.
In BaseModelAdmin
, it is first ensured that the user has permission to add, change or delete objects of the related model.
In RelatedFieldWidgetWrapper
, to change or delete a related object it is also ensured that the relation is not a many-to-many. Moreover, a related object cannot be deleted if the cascade delete is enabled for this relationship.
The permissions are by default True, I assume you would know if if you had changed them? If indeed you didn’t, the reason why you cannot change the related object might be that you overrid the readonly_fields
attribute in the admin model, or the get_readonly_fields
method.
Once you can see the change button, you will probably not yet see the delete button as the cascading is the default. You can change this by setting the on_delete
attribute when creating the foreign key.
2👍
look at __init__
function of class RelatedFieldWidgetWrapper
in django/contrib/admin/widgets.py
:
self.can_delete_related = not multiple and not cascade and can_delete_related
- [Django]-'WSGIRequest' object has no attribute 'get' when executing form.is_valid()
- [Django]-Django admin raw_id_fields table display
- [Django]-How to get checkbox values in django application
- [Django]-Django contenttype and string comparison
- [Django]-Django – Establishing Many To Many Relationship Between 2 Models Without Through Table Using Formsets