1👍
✅
Use User.get_all_permissions()
to get all permissions that the user has including permissions inherited from groups or use User.get_group_permissions
to get all permissions that a user has from their groups
jack_permissions = jack.get_all_permissions()
0👍
I presume your many-to-one relation chain is like the following:
User > Group > Permission
And you want to get all permissions related to a particular user. If so, you can use double-underscore (__
) notation to get the through relationship.
Does this get you what you want?
jack = User.objects.get(username="jack")
jack_permissions = Permission.objects.filter(group__users=jack)
- [Answered ]-NoReverseMatch error using get_absolute_url()
- [Answered ]-Django JWT asking for username/password
- [Answered ]-Django Error: cannot import name autodiscover_modules
- [Answered ]-Python manage.py syncdb doesn't create a table
- [Answered ]-Security when using MyModel.objects.get(name=some_var) in Django
Source:stackexchange.com