diff --git a/crowdsourcer/management/commands/import_national_data.py b/crowdsourcer/management/commands/import_national_data.py index e7bbc4a..b3b7881 100644 --- a/crowdsourcer/management/commands/import_national_data.py +++ b/crowdsourcer/management/commands/import_national_data.py @@ -175,10 +175,13 @@ def get_score(self, q, row, details, authority): score = 0 desc = "No" else: - for opt in details["options"]: - if opt["score"] == score: - desc = opt["desc"] - break + if details.get("options"): + for opt in details["options"]: + if opt["score"] == score: + desc = opt["desc"] + break + else: + desc = None return desc, score @@ -271,7 +274,12 @@ def import_answers(self, user, rt, df, q, details): option = None if not details.get("update_points_only", False): try: - option = Option.objects.get(question=q, description=score_desc) + if score_desc is not None: + option = Option.objects.get( + question=q, description=score_desc + ) + else: + option = Option.objects.get(question=q, score=score) except Option.DoesNotExist: self.print_info( f"No option found for {q.number}, {score_desc}, {authority.name}",