Last active
August 9, 2023 11:08
-
-
Save tudormunteanu/d1e7b32d24da81408a886deaf21f07df to your computer and use it in GitHub Desktop.
Add permissions to all staf members for new models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import migrations | |
from django.contrib.auth import get_user_model | |
from django.contrib.auth.models import Permission | |
User = get_user_model() | |
def assign_permissions_to_staff_users(apps, schema_editor): | |
perms = Permission.objects.filter(content_type__app_label='smart_actions') | |
staff_users = User.objects.filter(is_staff=True) | |
for user in staff_users: | |
for perm in perms: | |
user.user_permissions.add(perm) | |
class Migration(migrations.Migration): | |
dependencies = [ | |
('smart_actions', '0002_alter_smartactionattempt_context'), | |
] | |
operations = [ | |
migrations.RunPython(assign_permissions_to_staff_users), | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment