Make command "init_groups" assign "padawan" group to all users

parent aaf50250
from django.core.management.base import BaseCommand
from django.contrib.auth.models import Group, Permission
from django.contrib.auth.models import User, Group, Permission
groups = ["jedi", "padawan"]
permissions = {
......@@ -20,3 +20,7 @@ class Command(BaseCommand):
new_group, created = Group.objects.get_or_create(name=g)
for p in permissions[g]:
new_group.permissions.add(Permission.objects.get(codename=p))
users = User.objects.all()
for user in users:
user.groups.add(Group.objects.get(name="padawan"))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment