Banner groups.
[wolnelektury.git] / src / social / migrations / 0006_legacy_group.py
diff --git a/src/social/migrations/0006_legacy_group.py b/src/social/migrations/0006_legacy_group.py
new file mode 100644 (file)
index 0000000..f6881a3
--- /dev/null
@@ -0,0 +1,26 @@
+from django.db import migrations
+
+
+def legacy_group(apps, schema_editor):
+    Cite = apps.get_model('social', 'Cite')
+    BannerGroup = apps.get_model('social', 'BannerGroup')
+
+    traditional = BannerGroup.objects.create(name='Tradycyjne cytaty')
+    banners = BannerGroup.objects.create(name='Bannery')
+
+    Cite.objects.exclude(book=None).update(group=traditional)
+    Cite.objects.filter(book=None).update(group=banners)
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('social', '0005_auto_20190318_1309'),
+    ]
+
+    operations = [
+        migrations.RunPython(
+            legacy_group,
+            migrations.RunPython.noop
+        )
+    ]