Skip to content

Instantly share code, notes, and snippets.

@ilya-muhortov
Created January 29, 2020 00:33
Show Gist options
  • Save ilya-muhortov/e211bd59ebea6c21c76d76221ecb84fc to your computer and use it in GitHub Desktop.
Save ilya-muhortov/e211bd59ebea6c21c76d76221ecb84fc to your computer and use it in GitHub Desktop.
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment