# Generated by Django 2.2.27 on 2022-08-26 12:39

from django.db import migrations


def move_amounts(apps, schema_editor):
    Club = apps.get_model('club', 'Club')
    for club in Club.objects.all():
        for amount in [int(x) for x in club.single_amounts.split(',')]:
            club.singleamount_set.create(amount=amount)
        for amount in [int(x) for x in club.monthly_amounts.split(',')]:
            club.monthlyamount_set.create(amount=amount)


def move_amounts_back(apps, schema_editor):
    Club = apps.get_model('club', 'Club')
    for club in Club.objects.all():
        club.single_amounts = ','.join(
            str(x) for x in
            club.singleamount_set.order_by('amount')
        )
        club.monthly_amounts = ','.join(
            str(x) for x in
            club.monthlyamount_set.order_by('amount')
        )
        club.save()


class Migration(migrations.Migration):

    dependencies = [
        ('club', '0040_amount'),
    ]

    operations = [
        migrations.RunPython(
            move_amounts,
            move_amounts_back
        )
    ]
