Browse Source

Pokus 1 o opravu zaměření

middleware_test
Pavel "LEdoian" Turinsky 3 years ago
parent
commit
d1864c961e
  1. 34
      seminar/migrations/0095_fix_zamereni.py

34
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),
]
Loading…
Cancel
Save