Answer the question
In order to leave comments, you need to log in
How to allow users to view all posts in the admin panel?
How to allow users to view all posts in the admin panel, BUT not give the right to edit the post.
I'm still learning Django.
I have two user groups.
There are three rules: add_*, change_*, delete_*
As I understand it, in order for users to be able to view all records of a certain model, they need to assign the change_MODEL rule to them, but at the same time they can already edit the record. How can I do better. They need to see everything, but not edit anything)
Thank you!
Answer the question
In order to leave comments, you need to log in
Alternatively, you can use the get_readonly_fileds
I.e. despite the fact that the user has rights change_*
, he will not be able to edit in fact, because. all fields will be closed for editing.
class BaseAdmin(admin.ModelAdmin):
def get_readonly_fields(self, request, obj=None):
if 'имя группы пользователей' in [g.name for g in request.user.groups.all()]:
return self.get_fields(request, obj)
return None
BaseAdmin
in order not to manually override this method.@admin.register(MyModel)
class MyModelAdmin(BaseAdmin):
pass
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question