Django Admin - Group Permissions To Edit Or View Models
I'm searching for a way to customize the Django Administration to support permissions based on the user group. For example, I've just created the Developers group, now I've also cr
Solution 1:
ModelAdmin has three methods dealing with user permission: has_add_permission, has_change_permission and has_delete_permission. All three should return boolean (True/False).
So you could do something like:
classTicketAdmin(admin.ModelAdmin):
...
defhas_add_permission(self, request):
return request.user.groups.filter(name='Developers').exists()
defhas_change_permission(self, request, obj=None):
return request.user.groups.filter(name='Developers').exists()
defhas_delete_permission(self, request, obj=None):
return request.user.groups.filter(name='Developers').exists()
When False is returned from one of these, it's results in a 403 Forbidden.
Solution 2:
I had tried hours to find a way to edit custom admin's(based on my custom model) permission by some click on screen,without many coding.
Use Django's /admin/auth/user/ "User permissions:part"
Finally I find this: Just to install django-admin-view-permission
and I can change the staff's custom models' permission here

Also in the group part /admin/auth/group/add/ I can create a group has certain permission, and assign specific staff to their permission group.
Post a Comment for "Django Admin - Group Permissions To Edit Or View Models"