I've got a django app that I'm moving to rackspace. I have a model that uses FileFields and I'm using the django-storages library s3/boto backend. I want to use cloudfiles for storage, and I need to be able to serve up the old s3 content.
On a template page where I provide links to the files, I do this:
href="{{ static_url }}{{ article.code_archive_file}}"
static_url
is set from the view and equals settings.STATIC_URL
. Clearly this isn't going to work since settings.STATIC_URL
is going to change when I switch from s3.
Do I need to write a script to migrate all of my s3 files by hand to cloudfiles and also go through and update all the FileFields in my tables? (ugh). I'd rather be able to change out the storages backend and leave the old material in the s3 bucket.
If I do need to migrate the files and the fields, has someone already written a script for that?
bonus question: What best-practices didn't I follow when doing this? I've only been using django for about half a year now.
Option A: You can use a bit different paths on old and new storages and have something to decide from where file should be served. Something could be custom storage class, I think: you create storage class inherited from CloudFilesStorage, and in overrided url method it will either call super (if file is in the new storage) or call url method from S3BotoStorage (if file is in the old storage).
Option B: You can move your files to cloudfiles. I don't think you actually need to change anything in DB after that if you keep paths similar. Maybe you even don't need a script, just download files and then upload then (s3cmd can be used for downloading, cloudfiles probably got some tool for uploading too).
About best practices: you should've used media_url and DEFAULT_FILE_STORAGE instead of static_url and static storage. It's a good idea to keep project's static files (css/js/icons) and uploaded media separated.