Using Summernote on the Django project to add/remove posts via the Admin interface, I can find no solution for removing images from the Media Root. None of the similar responses found on SO work.
Works fine on images outside of Summernote - installed django-cleanup
What's the best way to delete image(s) when removing a post via Admin?
Have you tried django admin's delete_model method?
You can implement the delete_model method when certain actions are required before or after you delete the object from the Admin page.
from django.contrib import admin
from django_summernote.admin import SummernoteModelAdmin
class YourAdmin(SummernoteModelAdmin):
summernote_fields = '__all__'
def delete_model(self, request, obj):
# Delete an image before deleting an object
super().delete_model(request, obj)
# super().delete_model --> obj.delete()
# Delete an image after deleting an object
admin.site.register(YourModel, YourAdmin)
Since your project environment uses Summernote, Probably I know that you can implement the same by adding the above process through SummernoteModelAdmin.
Additional
If you want to erase multiple things at once, as shown in the picture above, you need to override the delete_queryset method.
For consistency when deleted from admin page, I think the delete_queryset method should also be overriding.
class YourAdmin(SummernoteModelAdmin):
summernote_fields = '__all__'
...
def delete_queryset(self, request, queryset):
for user in queryset:
self.delete_model(request, user)