I am trying to upload a file to django. So, I tried to use the code below to create a dynamic path for the file. But, it does not work.
I actually not sure how to use instance in model.py and how to pass path to def get_file_path.
Specifically, What I want is that pass the file path from the function in views.py.
For example, when I call something like docfile.save(filepath) , it will be saved in that filepath in django. Can you help me for this?
An example:
docfile.save(path1)
it will be saved in /path1/file_name
Note: path1 could be anything and it is not related to any model field.
You could for example have an extra field (e.g.
path) on the model that specifies the path which you could then access viainstance.pathinget_file_path. You can’t access arguments tosavein this function.