My use case is this: I'm using a custom filestorage backend to Amazon
S3. An inline model allows the upload of mp3 files and I am trying to
edit the ID3 tag on these before they get saved to backend. To
accomplish this, I've overridden the save_formset() on the parent
ModelAdmin to do a save(commit=False) and then I edit the instances
and save them individually.
The problem is that FieldFiles get saved to the storage backend even
on a save(commit=False), and (according to a more knowledgeable SeanL-
on #django), the FieldFile will only get saved once, the first time
through. So the only way I can accomplish what I want is to do two
saves to my backend -- one when the formset is saved with commit=False
and then I must call the storage backend's save() directly in order to
upload the changes I've made to the mp3 file in memory.
I think that the commit=False (or save=False in FieldFile.save() )
should not do the save to the storage backend. From what little I
could figure out with some help, the FieldFile would have to be saved
multiple times (but only one actually calling storage.save()) and that
could cause some transitory names on the FieldFile instance. For
example, on the commit=False, storage.get_available_name() would
return an available name for the file, but before the commit=True
happens, another process might save a file to the name given to the
first. In which case, when the first is actually saved, its filename
would have to change.
Another option might be to pass the save argument along to the storage
backend and give the backend designer control over the behavior --
perhaps to reserve a filename in a cache with a short ttl. This would
still require that the save() on FieldFile be called more than once
Incidentally, if anyone has a "proper" procedure for the actual
editing of the FieldFile's contents, I'd appreciate it if you could
pass that along as well. My way feels like nasty hackery.