# -*- coding: utf-8 -*- # Generated by Django 1.11b1 on 2017-03-18 20:02 from __future__ import unicode_literals from django.conf import settings from django.db import migrations, models import django.db.models.deletion def import_events(apps, schema_editor): # Fetching the models that have be moved from cof to gestion model_names = [ "Event", "EventCommentField", "EventCommentValue", "EventOption", "EventOptionChoice", "EventRegistration" ] models = [ (apps.get_model("cof", name), apps.get_model("gestion", name)) for name in model_names ] # Moving the data into the new table for OldModel, NewModel in models: NewModel.objects.bulk_create([ NewModel(**values) for values in OldModel.objects.values() ]) # Linking all the existing event to the COF group cof = apps.get_model("auth", "Group").objects.get(name="cof_buro") _, NewEvent = models[0] for event in NewEvent.objects.all(): event.associations.add(cof) def restore_events(apps, schema_editor): raise NotImplementedError class Migration(migrations.Migration): dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), ('auth', '0008_alter_user_username_max_length'), ('gestion', '0002_club_support'), ] operations = [ migrations.CreateModel( name='Event', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('title', models.CharField(max_length=200, verbose_name='Titre')), ('location', models.CharField(max_length=200, verbose_name='Lieu')), ('start_date', models.DateTimeField(blank=True, null=True, verbose_name='Date de début')), ('end_date', models.DateTimeField(blank=True, null=True, verbose_name='Date de fin')), ('description', models.TextField(blank=True, verbose_name='Description')), ('image', models.ImageField(blank=True, null=True, upload_to='imgs/events/', verbose_name='Image')), ('registration_open', models.BooleanField(default=True, verbose_name='Inscriptions ouvertes')), ('old', models.BooleanField(default=False, verbose_name='Archiver (événement fini)')), ('associations', models.ManyToManyField(related_name='events', to='auth.Group')), ], options={ 'verbose_name': 'Événement', }, ), migrations.CreateModel( name='EventCommentField', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=200, verbose_name='Champ')), ('fieldtype', models.CharField(choices=[('text', 'Texte long'), ('char', 'Texte court')], default='text', max_length=10, verbose_name='Type')), ('default', models.TextField(blank=True, verbose_name='Valeur par défaut')), ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='commentfields', to='gestion.Event')), ], options={ 'verbose_name': 'Champ', }, ), migrations.CreateModel( name='EventCommentValue', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('content', models.TextField(blank=True, null=True, verbose_name='Contenu')), ('commentfield', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='values', to='gestion.EventCommentField')), ], ), migrations.CreateModel( name='EventOption', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=200, verbose_name='Option')), ('multi_choices', models.BooleanField(default=False, verbose_name='Choix multiples')), ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='options', to='gestion.Event')), ], options={ 'verbose_name': 'Option des événements', 'verbose_name_plural': 'Options des événements' }, ), migrations.CreateModel( name='EventOptionChoice', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('value', models.CharField(max_length=200, verbose_name='Valeur')), ('event_option', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='choices', to='gestion.EventOption')), ], options={ 'verbose_name_plural': 'Choix', 'verbose_name': 'Choix', }, ), migrations.CreateModel( name='EventRegistration', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('paid', models.BooleanField(default=False, verbose_name='A payé')), ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='gestion.Event')), ('filledcomments', models.ManyToManyField(through='gestion.EventCommentValue', to='gestion.EventCommentField')), ('options', models.ManyToManyField(to='gestion.EventOptionChoice')), ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], options={ 'verbose_name': 'Inscription', }, ), migrations.AddField( model_name='eventcommentvalue', name='registration', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='gestion.EventRegistration'), ), migrations.AlterUniqueTogether( name='eventregistration', unique_together=set([('user', 'event')]), ), migrations.RunPython(import_events, restore_events), ]