From ad145ec70f5ac94e35d2f1db0c6e3a8af2c07dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Mon, 6 Jun 2016 11:05:33 +0200 Subject: [PATCH] Ajout des migrations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Création d'un tirage initial lié à tous les spectacles et participants existants --- bda/migrations/0002_add_tirage.py | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 bda/migrations/0002_add_tirage.py diff --git a/bda/migrations/0002_add_tirage.py b/bda/migrations/0002_add_tirage.py new file mode 100644 index 00000000..15865e5c --- /dev/null +++ b/bda/migrations/0002_add_tirage.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +from django.conf import settings +from django.utils import timezone + +def forwards_func(apps, schema_editor): + Tirage = apps.get_model("bda", "Tirage") + db_alias = schema_editor.connection.alias + Tirage.objects.using(db_alias).bulk_create([ + Tirage( + id=1, + title="Tirage de test (migration)", + active=True, + ouverture=timezone.now(), + fermeture=timezone.now()), + ]) + +def reverse_func(apps, schema_editor): + Tirage = apps.get_model("bda", "Tirage") + db_alias = schema_editor.connection.alias + Tirage.objects.using(db_alias).delete() + +class Migration(migrations.Migration): + + dependencies = [ + ('bda', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Tirage', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('title', models.CharField(max_length=300, verbose_name=b'Titre')), + ('ouverture', models.DateTimeField(verbose_name=b"Date et heure d'ouverture du tirage")), + ('fermeture', models.DateTimeField(verbose_name=b'Date et heure de fermerture du tirage')), + ('token', models.TextField(verbose_name=b'Graine du tirage', blank=True)), + ('active', models.BooleanField(default=True, verbose_name=b'Tirage actif')), + ], + ), + migrations.RunPython(forwards_func, reverse_func), + migrations.AlterField( + model_name='participant', + name='user', + field=models.ForeignKey(to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='participant', + name='tirage', + field=models.ForeignKey(default=1, to='bda.Tirage'), + preserve_default=False, + ), + migrations.AddField( + model_name='spectacle', + name='tirage', + field=models.ForeignKey(default=1, to='bda.Tirage'), + preserve_default=False, + ), + ]