# Generated by Django 4.2 on 2023-06-05 22:19

import app.base.forms.fields
from django.db import migrations, models


def merge_street(apps, schema_editor):
    Person = apps.get_model('base', 'Person')
    for x in Person.objects.all():
        x.street = f'{x.street} {x.house_nr}'
        x.save()


def split_street(apps, schema_editor):
    Person = apps.get_model('app.base', 'Person')
    for x in Person.objects.all():
        if ' ' in x.street:
            street, nr = x.street.rsplit(' ', 1)
        else:
            street, nr = x.street, '?'
        x.street = street.strip()
        x.house_nr = nr.strip()
        x.save()


class Migration(migrations.Migration):

    dependencies = [
        ('base', '0003_alter_transaction_time_stamp'),
    ]

    operations = [
        migrations.RunPython(merge_street, split_street),
        migrations.RemoveField(
            model_name='person',
            name='house_nr',
        ),
        migrations.AddField(
            model_name='person',
            name='created',
            field=app.base.forms.fields.DateField(
                default='1970-01-01', editable=False, verbose_name='Angelegt'),
            preserve_default=False,
        ),
        migrations.AlterField(
            model_name='person',
            name='street',
            field=models.CharField(
                max_length=200, verbose_name='Straße & Hausnummer'),
        ),
    ]
