Skip to content

Commit 83bcf16

Browse files
committed
fix(tool-admin): remove ToolAnswer records for unlinked catalogs
- Add default description when creating ToolAnswer. - Remove ToolAnswer entries for questions whose catalogs are no longer linked to the tool
1 parent 1585de7 commit 83bcf16

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

apps/tool_picker/admin.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,17 +290,20 @@ def save_related(self, request, form, formsets, change): # type: ignore[reportM
290290
defaults={
291291
"created_by": request.user,
292292
"modified_by": request.user,
293+
"description": "No description provided.", # Is this default description value acceptable?
293294
"ordinal_value": (
294295
OrdinalTypeEnum.NOT_AVAILABLE if question.question_type == QuestionTypeEnum.ORDINAL else None
295296
),
296297
},
297298
)
298-
299-
# If it already exists, just update modified_by
300299
if not created:
301300
tool_answer.modified_by = request.user # type: ignore[reportMissingTypeArgument]
302301
tool_answer.save(update_fields=["modified_by"])
303302

303+
ToolAnswer.objects.filter(tool=obj).exclude(
304+
question__catalog__in=obj.catalogs.all(),
305+
).delete()
306+
304307

305308
# ============================================================================
306309
# User Submission Models Admin

0 commit comments

Comments
 (0)