Skip to content

Commit

Permalink
Light simplification for duplicate_and_link_object
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurswag committed Oct 17, 2024
1 parent 3c689f9 commit abc33a5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions backend/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit abc33a5

Please sign in to comment.