# Generated by Django 3.2.12 on 2022-03-11 22:30

import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("froide_govplan", "0003_auto_20220228_1051"),
    ]

    operations = [
        migrations.AlterField(
            model_name="governmentplanscmsplugin",
            name="template",
            field=models.CharField(
                blank=True,
                choices=[
                    ("froide_govplan/plugins/default.html", "Normal"),
                    ("froide_govplan/plugins/progress.html", "Progress"),
                    ("froide_govplan/plugins/card_cols.html", "Card columns"),
                ],
                help_text="template used to display the plugin",
                max_length=250,
                verbose_name="template",
            ),
        ),
        migrations.CreateModel(
            name="GovernmentPlanFollower",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("email", models.CharField(blank=True, max_length=255)),
                ("confirmed", models.BooleanField(default=False)),
                (
                    "timestamp",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        verbose_name="Timestamp of Following",
                    ),
                ),
                ("context", models.JSONField(blank=True, null=True)),
                (
                    "content_object",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="followers",
                        to="froide_govplan.governmentplan",
                        verbose_name="Government plan",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="User",
                    ),
                ),
            ],
            options={
                "verbose_name": "Government plan follower",
                "verbose_name_plural": "Government plan followers",
                "ordering": ("-timestamp",),
                "get_latest_by": "timestamp",
                "abstract": False,
            },
        ),
        migrations.AddConstraint(
            model_name="governmentplanfollower",
            constraint=models.UniqueConstraint(
                condition=models.Q(("user__isnull", False)),
                fields=("content_object", "user"),
                name="unique_user_follower_froide_govplan_governmentplanfollower",
            ),
        ),
        migrations.AddConstraint(
            model_name="governmentplanfollower",
            constraint=models.UniqueConstraint(
                condition=models.Q(("user__isnull", True)),
                fields=("content_object", "email"),
                name="unique_email_follower_froide_govplan_governmentplanfollower",
            ),
        ),
    ]
