Reputation: 4197
Is there a built in way to assign functional permissions to users in Django? From documentations looks like Dajngo permissions are bound to Models.
For example, what I want is to create is 4 types of user groups: Normal users, Managers, Admins and Superadmin.
By default users in different groups will have access to perform different kinds of actions. For example users in Admin group can perform Task1, Task2 and Task3, but users in Managers group can only perform Task1 and Task2(no matter in which app these Tasks are).
Further, user permissions can be modified for a user to revoke access from performing certain task. For example, by default all Admins can perform Task1, Task2 and Task3, but a particular admin's permission can be modified to perform only Task1 and Task3.
Can this be achieved by build in Django permissions and groups or will need to write own permission system(or is there third-party Django app to do this)?
If it will be better to write own permission and group system, any suggestion for design to follow.
Thanks!
Upvotes: 0
Views: 774
Reputation: 1129
You can set the permissions in the admin page like foo.can_write or in your own view like
myuser.user_permissions.add(permission, permission, ...)
In the view you can set the permissions needed for some action. From documentations:
from django.contrib.auth.decorators import permission_required
@permission_required('polls.can_vote')
def my_view(request):
Upvotes: 1