From fd5b22169fd0f1ca3ba3a00b9cc0aeec2a4f4537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Wed, 13 Jul 2016 10:46:46 +0200 Subject: [PATCH] Update migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use les `bd_alias` de Django - N'ajoute le 'before """"""' dans la liste des tokens si le champ token était précédement vide. --- bda/migrations/0004_add_tirage_switch.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bda/migrations/0004_add_tirage_switch.py b/bda/migrations/0004_add_tirage_switch.py index 1f566b6d..7429197b 100644 --- a/bda/migrations/0004_add_tirage_switch.py +++ b/bda/migrations/0004_add_tirage_switch.py @@ -4,14 +4,17 @@ from __future__ import unicode_literals from django.db import migrations, models from django.utils import timezone + def forwards_func(apps, schema_editor): Tirage = apps.get_model("bda", "Tirage") db_alias = schema_editor.connection.alias - for tirage in Tirage.objects.all(): - tirage.tokens = "Before %s\n\"\"\"%s\"\"\"\n" % ( - timezone.now().strftime("%y-%m-%d %H:%M:%S"), - tirage.tokens) - tirage.save() + for tirage in Tirage.objects.using(db_alias).all(): + if tirage.tokens: + tirage.tokens = "Before %s\n\"\"\"%s\"\"\"\n" % ( + timezone.now().strftime("%y-%m-%d %H:%M:%S"), + tirage.tokens) + tirage.save() + class Migration(migrations.Migration):