What your looking for is exactly achieved by providing a custom
default file storage class.

Have a look at:
http://docs.djangoproject.com/en/1.2/ref/settings/#default-file-storage
http://docs.djangoproject.com/en/1.2/topics/files/#file-storage

Here's a simple example of how it might work in your case:

# settings.py
DEFAULT_FILE_STORAGE = 'core.models.ImageStorage'
FILE_STORAGE_LOCATION = os.path.join(os.path.dirname(__file__),
*('media', 'images'))
FILE_STORAGE_BASE_URL = MEDIA_URL + 'images/'

# models.py
class ImageStorage(FileSystemStorage):

    def __init__(self, location=None, base_url=None):
        location = location or settings.FILE_STORAGE_LOCATION
        base_url = base_url or settings.FILE_STORAGE_BASE_URL
        super(DocumentStorage, self).__init__(location, base_url)

So now `ImageStorage` is the default storage class for all your model
file fields and, by default, all uploaded files are stored in '/media/
images/'.

On Jan 11, 6:25 pm, Eric Chamberlain <[email protected]> wrote:
> You might want to look at django-storages 
> <https://bitbucket.org/david/django-storages/wiki/Home>.  We use it with S3.
>
> On Jan 10, 2011, at 4:55 PM, garagefan wrote:
>
>
>
> > so i bit the hype and got myself a rackspace cloud account. i also got
> > a rackspace file account for image serving. i would like to write
> > something that overrides where all images are saved, regardless of the
> > model that requests the save.
>
> > what would this be? would i make this a middleware? I assume i need to
> > extend and "replace" the default "save file to MEDIA_ROOT directory"
>
> > i havent had to extend or replace django's default behavior, so before
> > i start digging in to this, i need to know the best place for this...
> > which, i assume would be middleware. yes?
>
> > thanks!
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected].
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> Eric Chamberlain, Founder
> RF.com -http://RF.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to