Skip to main content

Command Palette

Search for a command to run...

Django admin tips and tricks - Part 2

Django admin tips and tricks

Updated
2 min read
Django admin tips and tricks - Part 2
G

Experienced Full Stack Software Engineer with 4+ Years of experience, proficient in Django and React, with expertise in Python, JavaScript and Typescript, also an author of Dev.Junction Blogs & YouTube Channel, expert in Python/Django, Rest Framework, ReactJS/NextJS and TypeScript, currently based in Pune, India.

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.

Django admin tips and tricks

Part 8 of 14

Django provides a great Admin panel rich in features and highly customizable, in this series of blogs we will be introduced to all such possible customizations and more.

Up next

Django admin tips and tricks - Part 1

Django admin tips and tricks