def initialize_matches(self): cm = ConnectorMatch() for cm_match in cm.fetch_all_match_data(): match = Match() match.id = cm_match['iId'] match.name = cm.fetch_match_data(match.id, 'name') match.date = cm.fetch_match_data(match.id, 'date') try: team_1 = Team.objects.get(id=cm.fetch_match_data(match.id, 'team_1')) match.team_1 = team_1 except Team.DoesNotExist: match.team_1 = None try: team_2 = Team.objects.get(id=cm.fetch_match_data(match.id, 'team_2')) match.team_2 = team_2 except Team.DoesNotExist: match.team_2= None match.cards = json.dumps(cm.fetch_match_data(match.id, 'cards')) match.description = cm.fetch_match_data(match.id, 'description') match.group = cm.fetch_match_data(match.id, 'group') match.score_1 = cm.fetch_match_data(match.id, 'score_1') match.score_2 = cm.fetch_match_data(match.id, 'score_2') match.goals = json.dumps(cm.fetch_match_data(match.id, 'goals')) match.result = cm.fetch_match_data(match.id, 'result') match.red_cards = json.dumps(cm.fetch_match_data(match.id, 'red_cards')) match.yellow_cards = json.dumps(cm.fetch_match_data(match.id, 'yellow_cards')) match.save()