# Generated by Django 5.1 on 2024-10-17 13:02 from ast import Match from django.db import migrations from tournaments.models.player_registration import PlayerRegistration def update_group_stage_store_id(apps): GroupStage = apps.get_model('tournaments', 'GroupStage') for group_stage in GroupStage.objects.all(): group_stage.store_id = str(group_stage.tournament.id) group_stage.save() def update_round_store_id(apps): Round = apps.get_model('tournaments', 'Round') for round in Round.objects.all(): round.store_id = str(round.tournament.id) round.save() def update_team_registration_store_id(apps): TeamRegistration = apps.get_model('tournaments', 'TeamRegistration') for tr in TeamRegistration.objects.all(): tr.store_id = str(tr.tournament.id) tr.save() def update_player_registration_store_id(apps): PlayerRegistration = apps.get_model('tournaments', 'PlayerRegistration') for pr in PlayerRegistration.objects.all(): pr.store_id = str(pr.team_registration.tournament.id) pr.save() def update_match_store_id(apps): Match = apps.get_model('tournaments', 'Match') for match in Match.objects.all(): if match.round: tournament = match.round.tournament else: tournament = match.group_stage.tournament match.store_id = str(tournament.id) match.save() def update_team_score_store_id(apps): TeamScore = apps.get_model('tournaments', 'TeamScore') for team_score in TeamScore.objects.all(): tournament = None if team_score.team_registration: tournament = team_score.team_registration.tournament elif team_score.match: if team_score.match.round: tournament = team_score.match.round.tournament else: tournament = team_score.team_registration.tournament team_score.store_id = str(tournament.id) team_score.save() def update_models(apps, schema_editor): update_group_stage_store_id(apps) update_round_store_id(apps) update_team_registration_store_id(apps) update_player_registration_store_id(apps) update_match_store_id(apps) update_team_score_store_id(apps) class Migration(migrations.Migration): dependencies = [ ('tournaments', '0089_groupstage_store_id_match_store_id_and_more'), ] operations = [ migrations.RunPython(update_models), ]