Skip to content

Instantly share code, notes, and snippets.

@madewulf
Created January 30, 2024 11:52
Show Gist options
  • Save madewulf/1718513dca6bf8e07625feab66d04c1a to your computer and use it in GitHub Desktop.
Save madewulf/1718513dca6bf8e07625feab66d04c1a to your computer and use it in GitHub Desktop.
Remove permission to a set of users
from iaso.models import *
from django.contrib.auth.models import Permission
permission = Permission.objects.get(codename="iaso_completeness")
acc = Account.objects.get(id=20)
profiles = Profile.objects.filter(account=acc).filter(user__user_permissions=permission)
c = 0
print("permission", permission)
for profile in profiles:
print(profile)
profile.user.user_permissions.remove(permission)
c+=1
print(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment