views:

22

answers:

1

Does deleting a Django Model object with a File field delete the storage used for the file? Does it delete the file on disk?

+3  A: 

OMG, I sure hope not! Talk about your quick trip to the land of tears.

If you want the storage freed up then you should override the model's .delete() method, delete the file, and then super() to let the DB finish its clean up.

Update: I was wrong ... maybe. From looking at the code in django/db/fields/files.py (ver 1.1.1) I can see that under certain circumstances, depending on which storage object class you are using, it may (or may not) delete the associated storage. Unfortunately, when and why is inconsistent and there is a 2+ year old ticket open on this ambiguity. The default_storage class does delete the associated file, but not reliably (see above mentioned ticket).

This means you need to be careful and to test the specific storage class you are using before you have important data end up in an indeterminate state.

Peter Rowell