I want to remove the Delete button from django admin page as shown below.

In your ModelAdmin definition you can override the function has_delete_permission. If you wish to remove the delete button for all users you can just return False
def has_delete_permission(self, request, obj=None):
return False
I would suggest however that you allow superusers to still be able to delete
def has_delete_permission(self, request, obj=None):
return request.user.is_superuser
You can override the function has_delete_permission to prevent deletion
def has_delete_permission(self, request, obj=None):
return False
Overriding has_delete_permission will prevent deletion in other model pages which have relation (with on_delete=models.CASCADE) to your model. To allow deletion in other pages but prevent the deletion in the model's admin page, You can conditionally return False like:
def has_delete_permission(self, request, obj=None):
if f"{model._meta.app_label}/{model._meta.model_name}" in request.path:
return False
return True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With