Opened 19 years ago

Closed 17 years ago

Last modified 16 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

Description

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@…> 19 years ago.

Download all attachments as: .zip

Change History (6)

by Adam Endicott <leftwing17@…>, 19 years ago

Attachment: diff.txt added

comment:1 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedDesign decision needed

comment:2 by Philippe Raoult, 17 years ago

Owner: changed from nobody to Philippe Raoult
Status: newassigned

will be solved by #5361

comment:3 by James Bennett, 17 years ago

Resolution: duplicate
Status: assignedclosed

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

comment:4 by Marty Alchin, 17 years ago

Keywords: fs-rf added

comment:5 by anonymous, 16 years ago

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