From 26a977e1f028d8d13c3c5f0eee538987f5db71b5 Mon Sep 17 00:00:00 2001 From: juuso-j Date: Fri, 2 Feb 2024 14:05:58 +0200 Subject: [PATCH] Fix SubQuestionConditions created on every import --- profiles/management/commands/import_questions.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/profiles/management/commands/import_questions.py b/profiles/management/commands/import_questions.py index 0039149..3798d05 100644 --- a/profiles/management/commands/import_questions.py +++ b/profiles/management/commands/import_questions.py @@ -113,7 +113,7 @@ def create_sub_question_condition(row_data: str, sub_question: SubQuestion): question_number, option_order_number = row_data.split(".") question = Question.objects.get(number=question_number) option = Option.objects.get(question=question, order_number=option_order_number) - SubQuestionCondition.objects.create(sub_question=sub_question, option=option) + SubQuestionCondition.objects.get_or_create(sub_question=sub_question, option=option) @db.transaction.atomic @@ -266,7 +266,6 @@ def handle(self, *args, **options): # Question.objects.all().delete() # QuestionCondition.objects.all().delete() # Result.objects.all().delete() - file_path = f"{get_root_dir()}/media/{FILENAME}" excel_data = pd.read_excel(file_path, sheet_name="Yhdistetty") excel_data = excel_data.fillna("").replace([""], [None])