I'm trying to make all fields readonly without listing them explicitly.
Something like:
class CustomAdmin(admin.ModelAdmin): def get_readonly_fields(self, request, obj=None): if request.user.is_superuser: return self.readonly_fields return self.fields
The problem is CustomAdmin.fields
is not set at this point.
Any ideas?
Since django 2.1, you can prevent editing, while allowing viewing, by returning False
from the ModelAdmin
's has_change_permission
method, like this:
class CustomAdmin(admin.ModelAdmin): def has_change_permission(self, request, obj=None): return False
(This will not work before django 2.1, as it will also deny permission to any user trying only to view.)
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