Opened 14 years ago

Closed 13 years ago

#15646 closed Bug (fixed)

Document that the FileField's path can not be relied on until the model is saved

Reported by: anonymous Owned by: nobody
Component: Documentation Version: 1.2
Severity: Normal Keywords: storage system path upload_to
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The FileField's .path attribute misses the path given in 'upload_to'.

Example:
In settings.py:

MEDIA_ROOT = '/somewhere/'

In some model:

data = models.FileField(upload_to='files')

In the view that handles the file upload:

print data.path

This prints '/somewhere/filename' but if I am correct it shall print '/somewhere/files/filename'
Exact Version is 1.2.5(-1) (current version in debian/wheezy)
upload_to='files/' does not remedy this issue.
I sincerely hope that I am not wasting your time.
Thank you.

Attachments (1)

15646.diff (1.3 KB ) - added by Dan Poirier 13 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by anonymous, 14 years ago

ADDENDUM:

Saving the instance apparently constructs the right path and fills it in. Due to the fact, that uploaded files often need processing -- for instance converting them to a different file format -- I would find it most reasonable to change that behaviour. Please consider.

Thank you.

comment:2 by anonymous, 14 years ago

Component: File uploads/storageDocumentation
Triage Stage: UnreviewedAccepted

This is #10788. It was determined back then that it is not fixable in a reasonable fashion, so the change from previous was documented in the release notes:

http://docs.djangoproject.com/en/1.1/releases/1.1/#names-of-uploaded-files-are-available-later

However I don't see that we documented this anywhere in the main docs, and we should. (Or maybe we do, and I just can't find it...I can't seem to find anywhere that we actually document the path attribute of a model FileField?) Accepting as a ticket against the docs.

comment:3 by Karen Tracey, 14 years ago

(Sorry, that was me. Somehow I can now post as anonymous where in the past I'd always get the rejected as potential spam message on anything as soon as trac logged me out.)

comment:4 by Luke Plant, 14 years ago

Type: Bug

comment:5 by Luke Plant, 14 years ago

Severity: Normal

comment:6 by Chris Beaven, 14 years ago

Easy pickings: unset
Summary: FileField's path attribute lacks 'upload_to' bit.Document that the FileField's path can not be relied on until the model is saved

comment:7 by Dan Poirier, 13 years ago

Owner: changed from nobody to Dan Poirier
Status: newassigned
UI/UX: unset

by Dan Poirier, 13 years ago

Attachment: 15646.diff added

comment:8 by Dan Poirier, 13 years ago

Easy pickings: set
Has patch: set

comment:9 by Dan Poirier, 13 years ago

Owner: changed from Dan Poirier to nobody
Status: assignednew

comment:10 by Karen Tracey, 13 years ago

Resolution: fixed
Status: newclosed

In [17113]:

Fix #15646: Document that a FileField's full path can't be relied upon until its model has been saved to the database. Thanks poirier.

Note: See TracTickets for help on using tickets.
Back to Top