In my models I have Document
model with foreign key to the Library
model.
When I am in Django admin site I want to disable editing and deleting Library
instances when I am creating new Document
.
What I tried was to remove delete and edit permissions by subclassing django.contrib.admin.ModelAdmin
and removing change/delete permissions
@admin.register(Library)
class LibraryAdmin(admin.ModelAdmin):
def has_delete_permission(self, request, obj=None):
return False
def has_change_permission(self, request, obj=None):
return False
This makes unwanted buttons disappear but also entirely blocks possibility of editing and removing Libraries
, which is not what I want. Is there a way to disable these actions only in model edit form?