# Generated by Django 2.1.15 on 2023-04-27 06:00

from django.db import migrations, models
from django.utils import timezone


def migrate_to_is_deleted(apps, schema_editor):
    Address = apps.get_model("addressbook", "Address")

    for address in Address.objects.all():
        if address.status == 2:
            address.is_deleted = True
            address.save(update_fields=("is_deleted",))


def migrate_from_is_deleted(apps, schema_editor):
    Address = apps.get_model("addressbook", "Address")

    for address in Address.objects.all():
        if address.is_deleted:
            address.status = 2
            address.save(update_fields=("status",))


class Migration(migrations.Migration):
    dependencies = [
        ("addressbook", "0001_initial"),
    ]

    operations = [
        migrations.AlterField(
            model_name="address",
            name="country",
            field=models.ForeignKey(
                on_delete=models.PROTECT,
                to="addressbook.Country",
                verbose_name="country",
            ),
        ),
        migrations.AlterField(
            model_name="address",
            name="created",
            field=models.DateTimeField(default=timezone.now, editable=False),
        ),
        migrations.AlterField(
            model_name="address",
            name="modified",
            field=models.DateTimeField(default=timezone.now, editable=False),
        ),
        migrations.AddField(
            model_name="address",
            name="is_deleted",
            field=models.BooleanField(default=False, verbose_name="is deleted"),
        ),
        migrations.RunPython(migrate_to_is_deleted, migrate_from_is_deleted),
        migrations.RemoveField(
            model_name="address",
            name="status",
        ),
    ]
