let update_to accept a callable
|Reported by:||Griffith Rees <griff.rees@…>||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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)