0018_add_groups_to_users.py 455 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from django.db import migrations
from django.contrib.auth.models import Group, User

def add_groups(apps, schema_editor):
    users = User.objects.all()
    padawanGroup = Group.objects.get(name='Padawan')

    for user in users:
        user.groups.add(padawanGroup)
        user.save()

class Migration(migrations.Migration):

    dependencies = [
        ('rp', '0017_groups'),
    ]

    operations = [
        migrations.RunPython(add_groups),
    ]