# Generated by Django 2.2.4 on 2019-11-22 07:02

from django.db import migrations


def get_flats_for_owners(apps, schema_editor):
    Flat = apps.get_model('property', 'Flat')
    Owner = apps.get_model('property', 'Owner')
    for owner in Owner.objects.all():
        flat, created = Flat.objects.get_or_create(owner=owner.name, owners_phonenumber=owner.phonenumber)
        owner.flat.add(flat)
        owner.save()


def move_backward(apps, schema_editor):
    Owner = apps.get_model('property', 'Owner')
    for owner in Owner.objects.all():
        owner.flat = ''
        owner.save()


class Migration(migrations.Migration):
    dependencies = [
        ('property', '0012_remove_flat_owner_link'),
    ]

    operations = [
        migrations.RunPython(get_flats_for_owners, move_backward),
    ]
