New layout pages.
[wolnelektury.git] / src / club / migrations / 0041_move_amounts.py
diff --git a/src/club/migrations/0041_move_amounts.py b/src/club/migrations/0041_move_amounts.py
new file mode 100644 (file)
index 0000000..d920fd0
--- /dev/null
@@ -0,0 +1,40 @@
+# 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
+        )
+    ]