Update migration

- Use les `bd_alias` de Django
- N'ajoute le 'before <date> """<ancien_token>"""' dans la liste des tokens
  si le champ token était précédement vide.
This commit is contained in:
Martin Pépin 2016-07-13 10:46:46 +02:00
parent 3aa9667eb9
commit fd5b22169f

View file

@ -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):