14👍
The Group
model has a ManyToMany
relationship with the Permission
model, so you can do this
for group in Group.objects.all():
permissions = group.permissions.all()
# do something with the permissions
9👍
To get all permissions in all groups the current user belongs to use this:
all_permissions_in_groups = user.get_group_permissions()
To get all permissions related to a user including ones that are not in any group do this:
all_permissions = user.get_all_permissions()
For more details see Django documentation
- Buildout vs virtualenv + pip for django?
- How to correctly use assertRaises in Django
- What are some alternative for ModelChoiceField for large number of choices?
- How do I update an object's members using a dict?
- Django long request timeout
1👍
If you have the name of the group, one way is:
from django.contrib.auth.models import Group
group_name = "test"
group_permissions = Group.objects.get(name=group_name).permissions.all()
- How to get max value in django ORM
- Django no module named "compressor"
- Django Pipeline, Heroku, and SASS
- How to make UUID field default when there's already ID field
- Django input element error css class
Source:stackexchange.com