Document how to change the path of a FileField
|Reported by:||Simon Litchfield||Owned by:||Jorge Barata|
|Severity:||Normal||Keywords:||filefield imagefield path filename|
|Cc:||ledermann@…, kitsunde@…, cmawebsite@…||Triage Stage:||Accepted|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Currently we can't set filefield/imagefield's underlying filename, without loading the file and feeding it's contents into save(). Obviously this is grossly inefficient.
This is a simple patch that allows you to set the path like so --
instance.myfile.path = 'uploads/new-path.avi'
Previously, instance.myfile.path is read only. If you set instance.myfile then instance.myfile.path etc will raise a ValueError, The 'myfile' attribute has no file associated with it.
Works with FileField, ImageField, and anything else that uses a File object that is subclassed from FieldFile.
Check stackoverflow, google, etc- lots of people banging their heads trying to figure out why they can't simply set the filename.
Change History (18)
comment:1 Changed 6 years ago by
|Patch needs improvement:||set|
|Triage Stage:||Unreviewed → Design decision needed|
comment:11 Changed 21 months ago by
|Component:||File uploads/storage → Documentation|
|Patch needs improvement:||unset|
|Summary:||FileField path isn't settable → Document how to change the path of a FileField|
comment:12 Changed 21 months ago by
|Owner:||changed from Simon Litchfield to Tim Graham|
|Status:||new → assigned|