Flatten the post data.
[audio.git] / src / archive / migrations / 0012_url_to_slug.py
1 # Generated by Django 3.0.6 on 2020-05-29 11:57
2
3 from django.db import migrations
4
5
6 def url_to_slug(apps, schema_editor):
7     Audiobook = apps.get_model('archive', 'Audiobook')
8     for a in Audiobook.objects.all():
9         a.slug = a.url.rstrip().rstrip('/').rsplit('/', 1)[-1]
10         a.save()
11
12 def slug_to_url(apps, schema_editor):
13     Audiobook = apps.get_model('archive', 'Audiobook')
14     for a in Audiobook.objects.all():
15         a.url = 'https://wolnelektury.pl/katalog/lektura/{}/'.format(a.slug)
16         a.save()
17
18
19 class Migration(migrations.Migration):
20
21     dependencies = [
22         ('archive', '0011_audiobook_slug'),
23     ]
24
25     operations = [
26         migrations.RunPython(
27             url_to_slug,
28             slug_to_url
29         )
30     ]