FileField - my variable used in "upload_to" parameter

46 views
Skip to first unread message

ciu...@gmail.com

unread,
Jun 19, 2006, 7:40:58 PM6/19/06
to Django users
Hi!

Is there way to change "upload_to" parameter's behaviour?
I see there is hardcoded strftime replacement.

What I want to achieve is to organise uploaded files with directories
named with uploading user's name. eg. MEDIA_ROOT/uploads/<user_id>/

Regards,
ciukes.

Jay Parlar

unread,
Jun 19, 2006, 11:40:54 PM6/19/06
to django...@googlegroups.com
As far as I know, the only way right now is to use the patch I wrote:
http://code.djangoproject.com/ticket/1994

Jay P.

mwtb

unread,
Jun 20, 2006, 3:43:39 AM6/20/06
to Django users

Jay's patch is cleaner, but if you don't want to patch Django, then
you can replace the upload_to attribute of the Image/FileField at
runtime, with something like (I can't check the syntax right now, so
this might be wrong) model._meta.get_field('my_field').upload_to =
'newpath'.

Obviously, you have to do this before Django does the save itself.

Damian Sinclair

Reply all
Reply to author
Forward
0 new messages