# Generated by Django 2.2.19 on 2021-08-03 18:35

from django.db import migrations


def set_resource(apps, schema_editor):
    BaseAdresse = apps.get_model("base_adresse", "BaseAdresse")
    RegionModel = apps.get_model("base_adresse", "RegionModel")
    DepartmentModel = apps.get_model("base_adresse", "DepartmentModel")
    CityModel = apps.get_model("base_adresse", "CityModel")
    AddressCacheModel = apps.get_model("base_adresse", "AddressCacheModel")
    if BaseAdresse.objects.exists():
        resource = BaseAdresse.objects.first()
        RegionModel.objects.update(resource=resource)
        DepartmentModel.objects.update(resource=resource)
        CityModel.objects.update(resource=resource)
        AddressCacheModel.objects.update(resource=resource)
    else:
        RegionModel.objects.all().delete()
        DepartmentModel.objects.all().delete()
        CityModel.objects.all().delete()
        AddressCacheModel.objects.all().delete()


class Migration(migrations.Migration):

    dependencies = [
        ('base_adresse', '0022_resource_in_models_add'),
    ]

    operations = [
        migrations.RunPython(set_resource),
    ]
