34 lines
		
	
	
	
		
			977 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
	
		
			977 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| # 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', '0095_fix_polymorphism'),
 | |
| 		('taggit', '0003_taggeditem_add_unique_index'),
 | |
| 	]
 | |
| 
 | |
| 	operations = [
 | |
| 		migrations.RunPython(fix_zamereni),
 | |
| 	]
 | 
