Merge pull request #2916 from ostcar/fix_group_migration

Fix the migration of the groups.
This commit is contained in:
Norman Jäckel 2017-01-30 16:26:37 +01:00 committed by GitHub
commit d338002592

View File

@ -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,
),
]