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)
Change History (11)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Component: | File uploads/storage → Documentation |
---|---|
Triage Stage: | Unreviewed → Accepted |
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 , 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 , 14 years ago
Type: | → Bug |
---|
comment:5 by , 14 years ago
Severity: | → Normal |
---|
comment:6 by , 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 , 13 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
UI/UX: | unset |
by , 13 years ago
Attachment: | 15646.diff added |
---|
comment:8 by , 13 years ago
Easy pickings: | set |
---|---|
Has patch: | set |
comment:9 by , 13 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
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.