Opened 17 years ago
Closed 17 years ago
#6714 closed (duplicate)
let update_to accept a callable
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | FileField Models | |
Cc: | andrew@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It would be nice if the upload_to parameter on FileFields accepted a callable as an argument. It could be called with the model instance as its only variable the first time the instance needed to be saved to disk (afterwards, it should rely on the database entry for the path).
Currently, it only accepts a formatting string, which means you cannot, for example, upload files to directories based on their filesize or other data (such as other attributes of the model instance).
class IssuePrintEdition(model.Model): issue = ForeignKey(Issue) # The issue this print edition is related to section = ForeignKey(Section) file = FileField(upload_to=upload_path) def upload_path(instance): return "issues/%s/%s" % (instance.issue.title, instance.section)
Note:
See TracTickets
for help on using tickets.
There's a whole bunch of design work going on in this area. Have a look in the archives of the django-developers list and in #5361 (which I'm going to mark this ticket as a duplicate of, since it's subsumed into that). It's not a trivial change for a number of reasons, but it's work in progress as part of a larger ongoing effort.