0

Django 1.3 do not removes file which was deleted from database. I'm not found how to set Django remove deleted files. Is it possible? If so, how?

I159
  • 29,741
  • 31
  • 97
  • 132

1 Answers1

2

Simple:

Override the delete and save and method in your model. Remember that a file can both be dereferenced by the deletion of the object, but also by uploading a new file. But beware that the delete method is not called when you delete in bulk, ie. QuerySet.delete().

https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods

You can also use signals:

https://code.djangoproject.com/wiki/Signals

But beware! The reason why Django does not automatically delete the file, is that it cannot guarantee that the file is not refered to by some other application or model. But if you can guarantee that as a programmer, go ahead.

This blog article gives you the best possible info, I think: http://haineault.com/blog/147/

benjaoming
  • 2,135
  • 1
  • 21
  • 29