# Generated by Django 3.1.13 on 2021-07-21 16:51

from django.db import migrations, models


class Migration(migrations.Migration):
    dependencies = [
        ("people", "0005_add_subscriptions"),
        ("data_france", "0027_eludepartemental"),
        ("elus", "0026_auto_20210721_1801"),
    ]

    operations = [
        migrations.RenameModel(
            old_name="RechercheParrainageMaire",
            new_name="RechercheParrainage",
        ),
        migrations.AlterModelOptions(
            name="rechercheparrainage",
            options={
                "permissions": [
                    ("acces_parrainages", "Donne l'accès à l'interface de parrainage")
                ],
                "verbose_name": "Parrainages pour la présidentielle",
                "verbose_name_plural": "Parrainages pour la présidentielle",
            },
        ),
        migrations.RenameField(
            model_name="rechercheparrainage",
            old_name="elu",
            new_name="maire",
        ),
        migrations.RemoveConstraint(
            model_name="rechercheparrainage",
            name="recherche_parrainage_un_seul_actif",
        ),
        migrations.AddField(
            model_name="rechercheparrainage",
            name="depute",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=models.deletion.SET_NULL,
                related_name="parrainages",
                related_query_name="parrainage",
                to="data_france.depute",
                verbose_name="Député·e",
            ),
        ),
        migrations.AddField(
            model_name="rechercheparrainage",
            name="elu_departemental",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=models.deletion.SET_NULL,
                related_name="parrainages",
                related_query_name="parrainage",
                to="data_france.eludepartemental",
                verbose_name="Élu·e départemental·e",
            ),
        ),
        migrations.AlterField(
            model_name="rechercheparrainage",
            name="maire",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=models.deletion.SET_NULL,
                related_name="recherches_parrainages",
                related_query_name="rechercher_parrainage",
                to="data_france.elumunicipal",
                verbose_name="Maire",
            ),
        ),
        migrations.AddConstraint(
            model_name="rechercheparrainage",
            constraint=models.UniqueConstraint(
                condition=models.Q(_negated=True, statut=5),
                fields=("maire",),
                name="parrainage_un_seul_actif_maire",
            ),
        ),
        migrations.AddConstraint(
            model_name="rechercheparrainage",
            constraint=models.UniqueConstraint(
                condition=models.Q(_negated=True, statut=5),
                fields=("elu_departemental",),
                name="parrainage_un_seul_actif_elu_departemental",
            ),
        ),
        migrations.AddConstraint(
            model_name="rechercheparrainage",
            constraint=models.UniqueConstraint(
                condition=models.Q(_negated=True, statut=5),
                fields=("depute",),
                name="parrainage_un_seul_actif_depute",
            ),
        ),
        migrations.AddConstraint(
            model_name="rechercheparrainage",
            constraint=models.CheckConstraint(
                check=models.Q(
                    models.Q(
                        ("elu_departemental__isnull", False),
                        ("maire__isnull", False),
                        _negated=True,
                    ),
                    models.Q(
                        ("depute__isnull", False),
                        ("maire__isnull", False),
                        _negated=True,
                    ),
                    models.Q(
                        ("depute__isnull", False),
                        ("elu_departemental__isnull", False),
                        _negated=True,
                    ),
                ),
                name="parrainage_un_seul_elu",
            ),
        ),
    ]
