diff --git a/seminar/migrations/0002_treenode_polymorphic_ctype.py b/seminar/migrations/0002_treenode_polymorphic_ctype.py deleted file mode 100644 index 4398be6c..00000000 --- a/seminar/migrations/0002_treenode_polymorphic_ctype.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 2.2.4 on 2019-08-13 19:36 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('contenttypes', '0002_remove_content_type_name'), - ('seminar', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='treenode', - name='polymorphic_ctype', - field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_seminar.treenode_set+', to='contenttypes.ContentType'), - ), - ] diff --git a/seminar/migrations/0003_problem_polymorphic_ctype.py b/seminar/migrations/0003_problem_polymorphic_ctype.py deleted file mode 100644 index 279efbf4..00000000 --- a/seminar/migrations/0003_problem_polymorphic_ctype.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 2.2.4 on 2019-08-13 19:45 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('contenttypes', '0002_remove_content_type_name'), - ('seminar', '0002_treenode_polymorphic_ctype'), - ] - - operations = [ - migrations.AddField( - model_name='problem', - name='polymorphic_ctype', - field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_seminar.problem_set+', to='contenttypes.ContentType'), - ), - ] diff --git a/seminar/migrations/0065_treenode_polymorphic_ctype.py b/seminar/migrations/0065_treenode_polymorphic_ctype.py new file mode 100644 index 00000000..71eef262 --- /dev/null +++ b/seminar/migrations/0065_treenode_polymorphic_ctype.py @@ -0,0 +1,31 @@ +# Generated by Django 2.2.4 on 2019-08-13 19:36 + +from django.db import migrations, models +import django.db.models.deletion + +def vyrob_treenodum_ctypes(apps, schema_editor): + # Kód zkopírovaný z dokumentace: https://django-polymorphic.readthedocs.io/en/stable/migrating.html + # XXX: Nevím, jestli se tohle náhodou nemělo spustit na všech childech (jen/i) + TreeNode = apps.get_model('seminar', 'TreeNode') + ContentType = apps.get_model('contenttypes', 'ContentType') + + new_ct = ContentType.objects.get_for_model(TreeNode) + TreeNode.objects.filter(polymorphic_ctype__isnull=True).update(polymorphic_ctype=new_ct) + + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ('seminar', '0064_auto_20190610_2358'), + ] + + operations = [ + migrations.AddField( + model_name='treenode', + name='polymorphic_ctype', + field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_seminar.treenode_set+', to='contenttypes.ContentType'), + ), + migrations.RunPython(vyrob_treenodum_ctypes, migrations.RunPython.noop), + ] diff --git a/seminar/migrations/0066_problem_polymorphic_ctype.py b/seminar/migrations/0066_problem_polymorphic_ctype.py new file mode 100644 index 00000000..f956217e --- /dev/null +++ b/seminar/migrations/0066_problem_polymorphic_ctype.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2.4 on 2019-08-13 19:45 + +from django.db import migrations, models +import django.db.models.deletion + +def vyrob_problemum_ctypes(apps, schema_editor): + # Kód zkopírovaný z dokumentace: https://django-polymorphic.readthedocs.io/en/stable/migrating.html + # XXX: Nevím, jestli se tohle náhodou nemělo spustit na všech childech (jen/i) + Problem = apps.get_model('seminar', 'Problem') + ContentType = apps.get_model('contenttypes', 'ContentType') + + new_ct = ContentType.objects.get_for_model(Problem) + Problem.objects.filter(polymorphic_ctype__isnull=True).update(polymorphic_ctype=new_ct) + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ('seminar', '0065_treenode_polymorphic_ctype'), + ] + + operations = [ + migrations.AddField( + model_name='problem', + name='polymorphic_ctype', + field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_seminar.problem_set+', to='contenttypes.ContentType'), + ), + migrations.RunPython(vyrob_problemum_ctypes, migrations.RunPython.noop), + ]