ptrad
[redakcja.git] / src / documents / migrations / 0019_fk_uses_id.py
1 # Generated by Django 4.1.9 on 2024-10-15 14:23
2
3 from django.db import migrations
4
5
6 def copy_slug_to_fk(apps, schema_editor):
7     cBook = apps.get_model('catalogue', 'Book')
8     dBook = apps.get_model('documents', 'Book')
9
10     for db in dBook.objects.all():
11         try:
12             cb = db.dc_slug
13         except cBook.DoesNotExist:
14             pass
15         else:
16             if cb is not None:
17                 db.catalogue_book = cb
18                 db.save()
19
20
21 class Migration(migrations.Migration):
22
23     dependencies = [
24         ("documents", "0018_book_catalogue_book_alter_book_catalogue_book_slug"),
25     ]
26
27     operations = [
28         migrations.RunPython(
29             copy_slug_to_fk,
30             migrations.RunPython.noop,
31         )
32     ]