Opened 9 years ago

Closed 7 years ago

Last modified 7 years ago

#651 closed enhancement (duplicate)

Allow directories in filename argument to save_<fieldname>_file

Reported by: Adam Endicott <leftwing17@…> Owned by: PhiR
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: UI/UX:

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

Download all attachments as: .zip

Change History (6)

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

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

  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by PhiR

  • Owner changed from nobody to PhiR
  • Status changed from new to assigned

will be solved by #5361

comment:3 Changed 7 years ago by ubernostrum

  • Resolution set to duplicate
  • Status changed from assigned to closed

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

comment:4 Changed 7 years ago by Gulopine

  • Keywords fs-rf added

comment:5 Changed 7 years ago by anonymous

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