From d1864c961e44ded4258a5378b6cb12bb0c81653c Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Thu, 29 Jul 2021 00:31:26 +0200 Subject: [PATCH] =?UTF-8?q?Pokus=201=20o=20opravu=20zam=C4=9B=C5=99en?= =?UTF-8?q?=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/migrations/0095_fix_zamereni.py | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 seminar/migrations/0095_fix_zamereni.py diff --git a/seminar/migrations/0095_fix_zamereni.py b/seminar/migrations/0095_fix_zamereni.py new file mode 100644 index 00000000..c7e7406c --- /dev/null +++ b/seminar/migrations/0095_fix_zamereni.py @@ -0,0 +1,34 @@ +# Generated by Django 2.2.24 on 2021-07-28 20:17 + +from django.db import migrations + +def fix_zamereni(apps, schema_editor): + ContentType = apps.get_model('contenttypes', 'ContentType') + Problem = apps.get_model('seminar', 'Problem') + ProblemCT = ContentType.objects.get_for_model(Problem) + TaggedItem = apps.get_model('taggit', 'TaggedItem') + + typy_problemu = [ + 'Clanek', + 'Tema', + 'Uloha', + 'Konfera', + ] + for typ in typy_problemu: + Model = apps.get_model('seminar', typ) + ModelCT = ContentType.objects.get_for_model(Model) + # Neumím jednoduše zjistit, které objekty jsou které, tak je prostě procyklím + for obj in Model.objects.all(): + TaggedItem.objects.filter(object_id=obj.problem_ptr.id, content_type=ProblemCT).update(content_type=ModelCT) + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0094_auto_20210701_0149'), + ('taggit', '0003_taggeditem_add_unique_index'), + ] + + operations = [ + migrations.RunPython(fix_zamereni), + ]