You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

34 lines
979 B

# 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),
]