# Generated by Django 2.2.9 on 2020-01-05 13:32

from django.conf import settings
from django.db import migrations, models


def move_profile_to_user(apps, schema_editor):
    Reponses = apps.get_model("propositions", "reponses")
    for answer in Reponses.objects.all():
        answer.user = answer.part.user
        answer.save()


def move_user_to_profile(apps, schema_editor):
    # One should do something similar to ``move_profile_to_user`` AND make the
    # ``part`` field temporarily nullable in the operations below.
    # => Grosse flemme
    raise NotImplementedError("Who uses migrations backwards anyway?")


class Migration(migrations.Migration):

    dependencies = [
        ("gestion", "0001_initial"),
        ("propositions", "0002_nom_verbose_name"),
    ]

    operations = [
        migrations.AlterModelOptions(
            name="reponses",
            options={
                "verbose_name": "Réponse à une proposition",
                "verbose_name_plural": "Réponses à une proposition",
            },
        ),
        migrations.RenameField(
            model_name="reponses", old_name="prop", new_name="proposition",
        ),
        migrations.AddField(
            model_name="reponses",
            name="user",
            field=models.ForeignKey(
                on_delete=models.deletion.CASCADE,
                to=settings.AUTH_USER_MODEL,
                null=True,
            ),
        ),
        migrations.RunPython(move_profile_to_user, move_user_to_profile),
        migrations.AlterField(
            model_name="reponses",
            name="user",
            field=models.ForeignKey(
                on_delete=models.deletion.CASCADE,
                to=settings.AUTH_USER_MODEL,
                null=False,
            ),
        ),
        migrations.RemoveField(model_name="reponses", name="part"),
        migrations.AddField(
            model_name="reponses",
            name="answer",
            field=models.CharField(
                choices=[("oui", "Oui"), ("non", "Non")],
                default="non",
                max_length=3,
                verbose_name="Réponse",
            ),
            preserve_default=False,
        ),
        migrations.AlterUniqueTogether(
            name="reponses", unique_together={("proposition", "user")},
        ),
        migrations.RemoveField(model_name="reponses", name="reponse",),
        migrations.RenameModel(old_name="reponses", new_name="answer"),
    ]
