# Generated by Django 3.2.18 on 2023-04-03 12:41
from django.conf import settings
from django.db import migrations, models
from django.utils import timezone


def add_certification_date_to_existing_certified_groups(apps, schema):
    now = timezone.now()
    SupportGroup = apps.get_model("groups", "SupportGroup")
    SupportGroup.objects.filter(
        subtypes__label__in=settings.CERTIFIED_GROUP_SUBTYPES
    ).update(certification_date=now)


class Migration(migrations.Migration):
    dependencies = [
        ("groups", "0016_uncertifiablegroup"),
    ]

    operations = [
        migrations.AddField(
            model_name="supportgroup",
            name="certification_date",
            field=models.DateTimeField(
                blank=True,
                default=None,
                help_text="La date à laquelle le groupe a été certifié, vide pour les groupes non certifiés",
                null=True,
                verbose_name="date de certification",
            ),
        ),
        migrations.RunPython(
            add_certification_date_to_existing_certified_groups,
            reverse_code=migrations.RunPython.noop,
        ),
    ]
