Django admin tips and tricks - Part 2

Django admin tips and tricks - Part 2

Django admin tips and tricks

If you want to read Part 1 of this blog, click on this link, for this whole series, click on this link.

How to disable Add button in the Django admin for certain Model admins?

Sometimes you do not want the admin to add new entries in a Model admin, here is how you disable the Add button, as given in the below image.

# app_name/admin.py

@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
    ...
    def has_add_permission(self, request, obj=None):
        return False

How to disable edit/change functionality in the Django admin for certain Model?

Sometimes you do not want the admin to edit/change the entries in a Model Admin, here is how you disable the change/edit functionality.

# app_name/admin.py

@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
    ...
    def has_change_permission(self, request, obj=None):
        return False

How to disable Delete functionality in the Django admin for certain Model:

Sometimes you do not want the admin to edit/change the entries in a Model Admin, here is how you disable the Delete functionality.

# app_name/admin.py

@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
    ...
    def has_delete_permission(self, request, obj=None):
        return False

This is it for this blog, let's meet in the next one.

Any thoughts? Write it down in the comments.

For more such crispy blogs daily, follow Dev.Junction, subscribe to our newsletter and get notified.

Did you find this article valuable?

Support Dev.Junction by becoming a sponsor. Any amount is appreciated!