Opened 13 years ago

Closed 12 years ago

Last modified 11 years ago

#651 closed enhancement (duplicate)

Allow directories in filename argument to save_<fieldname>_file

Reported by: Adam Endicott <leftwing17@…> Owned by: Philippe Raoult
Component: Core (Other) Version:
Severity: normal Keywords: fs-rf-fixed
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Currently, all files associated with FileFields are uploaded into a single directory specified by MEDIA_ROOT and upload_to. There is no way to specify directories on a per-file basis when files are uploaded. With this patch, if the filename argument to save_<fieldname>_file specifies a directory as well as a filename, the file will be uploaded to that directory under the MEDIA_ROOT/upload_to directory. Example:

class File(meta.Model):
    file = meta.FileField(upload_to='baseDir')
    name = meta.CharField(maxlength=100)
newFile = files.File(name='my file')
newFile.save_file_file('some/sub/directory/myFile.txt', 'Some text content')

The above lines will create a file at: <MEDIA_ROOT>/baseDir/some/sub/directory/myFile.txt.

This shouldn't change how most file uploading (including the admin app) works now, because normally just a filename without any directories is passed to save_<fieldname>_file. However, it allows custom view code or FileField subclasses (each of which will call save_<fieldname>_file) to save files to specific locations easily.

Attachments (1)

diff.txt (1.5 KB) - added by Adam Endicott <leftwing17@…> 13 years ago.

Download all attachments as: .zip

Change History (6)

Changed 13 years ago by Adam Endicott <leftwing17@…>

Attachment: diff.txt added

comment:1 Changed 12 years ago by Simon G. <dev@…>

Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 12 years ago by Philippe Raoult

Owner: changed from nobody to Philippe Raoult
Status: newassigned

will be solved by #5361

comment:3 Changed 12 years ago by James Bennett

Resolution: duplicate
Status: assignedclosed

Closing as a duplicate of #5361 per PhiR's comment above.

comment:4 Changed 11 years ago by Marty Alchin

Keywords: fs-rf added

comment:5 Changed 11 years ago by anonymous

Keywords: fs-rf-fixed added; fs-rf removed
Note: See TracTickets for help on using tickets.
Back to Top