From 6b5c32960565775d8b94825087c503e58f5eed27 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Fri, 27 Jan 2017 11:59:31 +0100 Subject: [PATCH] Fix the migration of the groups. Fixes #2915 --- openslides/users/migrations/0003_group.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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, + ), ]