Pavel "LEdoian" Turinsky
3 years ago
1 changed files with 34 additions and 0 deletions
@ -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…
Reference in new issue