Is there a way to make a model read-only in the django admin? but I mean the whole model.
So, no adding, no deleting, no changing, just see the objects and the fields, everything as read-only?
Is there a way to make a model read-only in the django admin? but
Share
ModelAdmin provides the hook get_readonly_fields() – the following is untested, my idea being to determine all fields the way ModelAdmin does it, without running into a recursion with the readonly fields themselves:
then subclass/mixin this admin whereever it should be a read-only admin.
For add/delete, and to make their buttons disappear, you’ll probably also want to add
P.S.: In ModelAdmin, if has_change_permission (lookup or your override) returns False, you don’t get to the change view of an object – and the link to it won’t even be shown. It would actually be cool if it did, and the default get_readonly_fields() checked the change permission and set all fields to readonly in that case, like above. That way non-changers could at least browse the data… given that the current admin structure assumes view=edit, as jathanism points out, this would probably require the introduction of a “view” permission on top of add/change/delete…
EDIT: regarding setting all fields readonly, also untested but looking promising:
EDIT: Here’s another one