In Django Admin how do I disable the Delete link
Simple :)
class DeleteNotAllowedModelAdmin(admin.ModelAdmin):
# Other stuff here
def has_delete_permission(self, request, obj=None):
return False
If you want to disable an specific one that isn't custom do this. In django 1.6.6 I had to extend get_actions
plus define has_delete_permission
. The has_delete_permission
solution does not get rid of the action from the dropdown for me:
class MyModelAdmin(admin.ModelAdmin):
....
def get_actions(self, request):
#Disable delete
actions = super(MyModelAdmin, self).get_actions(request)
del actions['delete_selected']
return actions
def has_delete_permission(self, request, obj=None):
#Disable delete
return False
Not including it in actions = ['your_custom_action']
, only works for the custom actions (defs) you have defined for that model. The solution AdminSite.disable_action('delete_selected')
, disables it for all models, so you would have to explicitly include them later per each modelAdmin