I want to retrieve all permission for user as list of premission id's but:
user.get_all_permissions()
give me list of permission names. How to do it?
to get all the permissions of a given user, also the permissions associated with a group this user is part of:
from django.contrib.auth.models import Permission
def get_user_permissions(user):
if user.is_superuser:
return Permission.objects.all()
return user.user_permissions.all() | Permission.objects.filter(group__user=user)