我写了以下代码:
def parse_match_data(self, match_data, statistics_data):
data = {"all_advanced_fields_populated": True}
if(match_data["match_hometeam_halftime_score"] == "" or match_data["match_hometeam_halftime_score"] == ""):
data["all_fields_populated"] = False
data["home_fh_goals"] = 0
data["home_sh_goals"] = 0
data["away_fh_goals"] = 0
data["away_sh_goals"] = 0
else:
data["all_fields_populated"] = True
data["home_sh_goals"] = 0 if int(match_data["match_hometeam_score"]) - int(match_data["match_hometeam_halftime_score"]) < 0 else int(match_data["match_hometeam_score"]) - int(match_data["match_hometeam_halftime_score"])
data["away_sh_goals"] = 0 if int(match_data["match_awayteam_score"]) - int(match_data["match_awayteam_halftime_score"]) < 0 else int(match_data["match_awayteam_score"]) - int(match_data["match_awayteam_halftime_score"])
data["home_fh_goals"] = int(match_data["match_hometeam_halftime_score"])
data["away_fh_goals"] = int(match_data["match_awayteam_halftime_score"])
required_keys = ["Ball Possession", "Goal Attempts", "Shots on Goal"]
if(statistics_data):
for statistic in statistics_data:
if(statistic["type"] in required_keys):
data["home_" + statistic["type"].lower().replace(" ", "_")] = statistic["home"].strip('%')
data["away_" + statistic["type"].lower().replace(" ", "_")] = statistic["away"].strip('%')
使用统计方法中函数的“创建”部分似乎update_or_create一切正常,但是当它需要“更新”一个项目时,它会引发以下错误:
慕沐林林
相关分类