I was just learning/dealing with this now.
example:
class Mix(models.Model):
mp3 = models.FileField(upload_to="mixes",blank=True)
# let's say the mix object already exists
mix = Mix.objects.get( .... etc )
# however you get a file
file = request.FILES[u'Filedata']
# swfupload is awesome btw.
or by opening it from your post processed folder somewhere
or by creating a file directly in memory using content, or PIL etc.
then the correct way is this:
if
mix.mp3.name: # if there is a previous file and we wish to delete it
mix.mp3.storage.delete(
mix.mp3.name )
get the field's defined storage to delete it
#name will be eg. "mixes/oldfile.mp3"
ideal_path = "mixes/newfile.mp3"
# save the new file into storage
saved_to = mix.mp3.storage.save( ideal_path, file )
the path may have _ added to it for non-clobber purposes and is returned with the real path
# assign the string directly to the file field input
mix.mp3 = saved_to
# and save the new path into the object
mix.save()
this is nice in that you can switch the storage later or use multiple storage systems across your site,
not just
from django.core.files.storage import default_storage
default_storage.save( path, file)
you can upload to "tempUploads/file.xxx" and then search for files whose names are still in tempUploads and thus not yet processed