`_DELETE` events not triggered by admin delete batch action
foucdeg opened this issue · 1 comments
foucdeg commented
The batch action in Django Admin that allows deleting instances (check a few lines in the list and select "delete" in the dropdown menu) does not trigger BEFORE_DELETE
and AFTER_DELETE
events.
This is understandable, as the action calls .delete()
on a queryset and not individual instances. However, I think it might be worth a notice in this library's documentation.
A workaround is to override ModelAdmin.delete_queryset
:
class BookAdmin(admin.ModelAdmin):
def delete_queryset(self, request: HttpRequest, queryset: QuerySet[Book]) -> None:
# Delete each instance individually to trigger the delete lifecycle hook.
for instance in queryset:
instance.delete()
EnriqueSoria commented
Definitely this is something that has to be in the docs, and it's in the roadmap: #143
Anyway, thanks for reporting it and suggest a workaround!