# Generated by Django 3.0.6 on 2020-05-29 11:57

from django.db import migrations


def url_to_slug(apps, schema_editor):
    Audiobook = apps.get_model('archive', 'Audiobook')
    for a in Audiobook.objects.all():
        a.slug = a.url.rstrip().rstrip('/').rsplit('/', 1)[-1]
        a.save()

def slug_to_url(apps, schema_editor):
    Audiobook = apps.get_model('archive', 'Audiobook')
    for a in Audiobook.objects.all():
        a.url = 'https://wolnelektury.pl/katalog/lektura/{}/'.format(a.slug)
        a.save()


class Migration(migrations.Migration):

    dependencies = [
        ('archive', '0011_audiobook_slug'),
    ]

    operations = [
        migrations.RunPython(
            url_to_slug,
            slug_to_url
        )
    ]
