Sorl-Thumbnail لا يحذف الملف الأصل أو ذاكرة التخزين المؤقت عند حذف الإدخال

StackOverflow https://stackoverflow.com/questions/5012829

سؤال

أنا لست متأكدا مما أفعله خطأ.لكن الملف الذي تم تحميله ولم يتم حذف ذاكرة التخزين المؤقت ذات الصلة عند حذفه عند حذف الإدخال.

لدي نموذج نموذج مضمن لنموذج خاصية، مع FK من نموذج الصور إلى نموذج العقار.أنا أستخدم "من sorl.thumbnail استيراد Imagefield" لاستبدال نماذج Django الافتراضية .imagefield.

في مسؤول Django، عندما أحذف إدخال الصورة، يتم حذف الإدخال ولكن الملفات الخاصة بهذا الإدخال لا يتم حذفها.أنا أستخدم Runserver Django للتطوير ولا أرى أي أخطاء.من ما قرأته، يجب إزالة هذه الملفات إذا تم حذف الإدخال، ما لم يكن هناك إشارة إليهم حتى الآن.المرجع الوحيد الذي أراه بعد في طاولة Thumbnail_kvstore.

أي شخص لديه أي أفكار حول ما أفتقده؟

هل كانت مفيدة؟

المحلول

The ImageField from sorl.thumbnail should be an extension of django's FileField

From the release notes of django 1.2.5:

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 potentially serious data-loss scenarios, including rolled-back transactions and fields on different models referencing the same file. In Django 1.2.5, 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).

نصائح أخرى

The delete_file method will only be called in Django < v1.2.5. The best way to delete sorl.thumbnail.ImageField files, thumbnails and key value store references (used by sorl thumbnail) is to use sorl.thumbnail.delete function: sorl.thumbnail.delete(self.photo)

I had the problem with django-filebrowser, and when you replaced the image with a new one, the cached files did not update. So in my case it wasn't an issue with sorl-thumbnail but rather with django-filebrowser. sorl would only re-draw the thumbnails when the path of the file changed. To fix this I set the filebrowser FILEBROWSER_OVERWRITE_EXISTING setting to False.

FILEBROWSER_OVERWRITE_EXISTING = False

This may help someone at least debug the issue if they are not using django-filebrowser. But in the case of django-filebrowser this is the way to go. Cheers.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top