From 56936c86ab90cf9a2d5f249a8a1fb5d44f0bcd38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Mon, 7 Mar 2016 18:54:05 +0100 Subject: [PATCH] Used bulk_create to create the initial projector during migration. Fixed #2035. --- openslides/core/migrations/0001_initial.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/openslides/core/migrations/0001_initial.py b/openslides/core/migrations/0001_initial.py index 6ffa3f415..e8092db39 100644 --- a/openslides/core/migrations/0001_initial.py +++ b/openslides/core/migrations/0001_initial.py @@ -2,7 +2,6 @@ # Generated by Django 1.9.2 on 2016-03-02 01:22 from __future__ import unicode_literals -import json import uuid import django.db.models.deletion @@ -13,15 +12,21 @@ from django.db import migrations, models import openslides.utils.models -def add_default_projector_via_sql(): +def add_default_projector(apps, schema_editor): """ Adds default projector and activates clock. """ + # We get the model from the versioned app registry; + # if we directly import it, it will be the wrong version. + Projector = apps.get_model('core', 'Projector') projector_config = {} projector_config[uuid.uuid4().hex] = { 'name': 'core/clock', 'stable': True} - return ["INSERT INTO core_projector (config, scale, scroll) VALUES ('{}', 0, 0);".format(json.dumps(projector_config))] + # We use bulk_create here because we do not want model's save() method + # to be called because we do not want our autoupdate signals to be + # triggered. + Projector.objects.bulk_create([Projector(config=projector_config)]) class Migration(migrations.Migration): @@ -105,5 +110,5 @@ class Migration(migrations.Migration): }, bases=(openslides.utils.models.RESTModelMixin, models.Model), ), - migrations.RunSQL(add_default_projector_via_sql()), + migrations.RunPython(add_default_projector), ]