# Generated by Django 5.0.6 on 2024-07-08 15:17

from django.db import migrations
from django.utils.text import slugify


def link_organizations(apps, schema_editor):
    Person = apps.get_model("sites_conformes_blog", "Person")
    Organization = apps.get_model("sites_conformes_blog", "Organization")
    for person in Person.objects.all():
        if person.organization:
            organization, _created = Organization.objects.get_or_create(
                name=person.organization, slug=slugify(person.organization)
            )
            person.organization_item = organization
            person.save()


class Migration(migrations.Migration):
    dependencies = [
        ("sites_conformes_blog", "0023_organization_person_organization_item"),
    ]

    operations = [
        migrations.RunPython(link_organizations, elidable=True),
    ]
