diff --git a/openslides/users/migrations/0003_group.py b/openslides/users/migrations/0003_group.py index 2e9e5e80f..6f32d4214 100644 --- a/openslides/users/migrations/0003_group.py +++ b/openslides/users/migrations/0003_group.py @@ -8,6 +8,19 @@ import openslides.users.models import openslides.utils.models +def create_openslides_groups(apps, schema_editor): + """ + Creates the users.models.Group objects for each existing + django.contrib.auth.models.Group object. + """ + # We get the model from the versioned app registry; + # if we directly import it, it will be the wrong version. + DjangoGroup = apps.get_model('auth', 'Group') + Group = apps.get_model('users', 'Group') + for group in DjangoGroup.objects.all(): + Group.objects.create(group_ptr_id=group.pk, name=group.name) + + class Migration(migrations.Migration): dependencies = [ @@ -35,4 +48,7 @@ class Migration(migrations.Migration): ('objects', openslides.users.models.GroupManager()), ], ), + migrations.RunPython( + create_openslides_groups, + ), ]