From abc33a53c79ff98868f82ac9f3735b4efc638b9b Mon Sep 17 00:00:00 2001 From: monsieurswag Date: Thu, 17 Oct 2024 19:41:26 +0200 Subject: [PATCH] Light simplification for duplicate_and_link_object --- backend/core/helpers.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/core/helpers.py b/backend/core/helpers.py index de424349f..daec326d5 100644 --- a/backend/core/helpers.py +++ b/backend/core/helpers.py @@ -1239,15 +1239,14 @@ def link_existing_object(duplicate_object, existing_obj, field_name): """ getattr(duplicate_object, field_name).add(existing_obj) - def duplicate_and_link_object(obj, duplicate_object, target_folder, field_name): + def duplicate_and_link_object(new_obj, duplicate_object, target_folder, field_name): """ Duplicate an object and link it to the duplicate object. """ - duplicate_obj = obj - duplicate_obj.pk = None - duplicate_obj.folder = target_folder - duplicate_obj.save() - getattr(duplicate_object, field_name).add(duplicate_obj) + new_obj.pk = None + new_obj.folder = target_folder + new_obj.save() + link_existing_object(duplicate_object, new_obj, field_name) # Get parent and sub-folders of the target folder target_parent_folders = target_folder.get_parent_folders()