I’ve got a model like this
def upload_location(instance, filename): return 'validate/%s/builds/%s' % (get_current_user(), filename) class MidletPair(models.Model): jad_file = models.FileField(upload_to = upload_location) jar_file = models.FileField(upload_to = upload_location) upload_to=tempfile.gettempdir()
How can I get the current user in upload_location()... ?
Side note: Looking up django stuff is confusing as theres a lot of pre-1.0 stuff around on the net.
The current user is stored in the request object, and you can’t get that in a model method unless you pass it in from elsewhere – which you can’t do in the upload_to function.
So you’ll need to approach this in a different manner – I would suggest doing it at the form level. You can pass the request object into the form’s
__init__method and store it in an instance attribute, where you can get to it in a custom upload handler. For documentation on upload handlers, look here.