ilya-muhortov
1/29/2020 - 12:33 AM

django replace path

import os
import pathlib
import shutil

path = pathlib.Path(instance.input_file.path)
new_input_path = os.path.join(path.parents[1], str(instance.id))
new_input_filepath = os.path.join(new_input_path, path.name)
shutil.move(str(path.parent), new_input_path)
input_file = str(pathlib.Path(new_input_filepath).relative_to(settings.MEDIA_ROOT))