From f9f8fb71279fb91e8673e794f8b183d1639bf567 Mon Sep 17 00:00:00 2001 From: Barbara Krautgartner Date: Mon, 18 Mar 2024 15:04:00 +0000 Subject: [PATCH] fix: create a new work if no siglum is provided get or create based on sigle is not sufficient, so in addition to sigle check we need to create a new work if siglum is empty --- apis_ontology/scripts/import_helpers.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/apis_ontology/scripts/import_helpers.py b/apis_ontology/scripts/import_helpers.py index 2480e0a..4eb60be 100644 --- a/apis_ontology/scripts/import_helpers.py +++ b/apis_ontology/scripts/import_helpers.py @@ -90,15 +90,20 @@ def create_work(title: str, subtitle: str, siglum: str, source: DataSource): :param source: DataSource object to link to, used to identify data imports :return: Work object """ - work, created = Work.objects.get_or_create( - siglum=siglum, - ) - if created: - work.title = title - work.subtitle = subtitle - work.data_source = source - work.save() + if siglum: + work, created = Work.objects.get_or_create( + siglum=siglum, + ) + + if created: + work.title = title + work.subtitle = subtitle + work.data_source = source + work.save() + else: + work = Work.objects.create(title=title, subtitle=subtitle, data_source=source) + created = True return work, created