views:

428

answers:

2

My deployment script overwrites the media and source directories which means I have to move the uploads directory out of the media directory, and replace it after the upload has been extracted.

How can I instruct django to upload to /uploads/ instead of /media/?

So far I keep getting django Suspicious Operation errors! :(

I suppose another solution might be a symlink?

Many thanks, Toby.

+1  A: 

check this out.

http://docs.djangoproject.com/en/dev/howto/custom-file-storage/

Brandon H
There must be a way of doing it without writing custom storage, surely?
Toby
Sorry, You are correct it can be done in two lines with FileSystemStorage. Thank you.
Toby
@Toby - can you post how you did it in two lines ?
thornomad
+8  A: 

Thornomad, I did the following:

upload_storage = FileSystemStorage(location=UPLOAD_ROOT, base_url='/uploads')

image = models.ImageField(upload_to='/images', storage=upload_storage)

UPLOAD_ROOT is defined in my settings.py file: /foo/bar/webfolder/uploads

I found a great example here: http://abing.gotdns.com/posts/2009/django-file-upload-handling-examples/

Hope that helps! Toby.

Toby
nice job. i just played with django filefields in an application i'm writing for work. i may end up going this route as well.
Brandon H
thanks for posting your solution - groovy
thornomad