FileField
(or ImageField
), I have to specify a upload_to
:
campo1 = models.FileField(upload_to="uploads")
campo2 = models.ImageField(upload_to="img/%Y/%m/%d")
In the first case, all files go to the "uploads" folder. In the second, they go to a different folder according to the year / month / day the upload occurred. In both cases, the folder is predefined.
I would like to upload to a subfolder of the one specified in upload_to
. For example:
subpasta = request.POST("subpasta") # Ex.: foo/bar
arq = request.FILEs("arquivo") # Ex.: baz.txt
meuModelo.campo1 = ... # Resultado esperado: MEDIA_ROOT/uploads/foo/bar/baz.txt
Is it possible to do this with FileField
of Django? Or - even if you can not save the file in this way - alternatively get a file that is already in a subfolder of upload_to
and simply make the template "point" to him?