Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
FileField no longer deletes files
In earlier Django versions, when a model instance containing a FileField was deleted, FileField took it upon itself to also delete the file from the backend storage. This opened the door to several data-loss scenarios, including rolled-back transactions and fields on different models referencing the same file. In Django 1.3, FileField will never delete files from the backend storage. If you need cleanup of orphaned files, you'll need to handle it yourself (for instance, with a custom management command that can be run manually or scheduled to run periodically via e.g. cron).
# my_storages.py
from django.core.files.storage import FileSystemStorage
class ReplacingFileStorage(FileSystemStorage):
def _save(self, name, content):
self.delete(name)
return super(ReplacingFileStorage, self)._save(name, content)
# settings.py
DEFAULT_FILE_STORAGE = 'my_storages.ReplacingFileStorage'
Релиз Django 1.3