Readonly models in Django admin interface?

The admin is for editing, not just viewing (you won’t find a “view” permission). In order to achieve what you want you’ll have to forbid adding, deleting, and make all fields readonly:

class MyAdmin(ModelAdmin):

    def has_add_permission(self, request, obj=None):
        return False

    def has_delete_permission(self, request, obj=None):
        return False

(if you forbid changing you won’t even get to see the objects)

For some untested code that tries to automate setting all fields read-only see my answer to Whole model as read-only

EDIT: also untested but just had a look at my LogEntryAdmin and it has

readonly_fields = MyModel._meta.get_all_field_names()

Don’t know if that will work in all cases.

EDIT: QuerySet.delete() may still bulk delete objects. To get around this, provide your own “objects” manager and corresponding QuerySet subclass which doesn’t delete – see Overriding QuerySet.delete() in Django

Leave a Comment