About the Delete Admin Action

The delete() method of a model is not called when you trigger the "delete" admin action. The records are deleted at the QuerySet level.

When you need to do some pre- or post-processing for each model instance with the "delete" admin action, you can overwrite the delete_queryset() method of the model admin:

admin.py

1
2
3
4
5
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    def delete_queryset(self, request, queryset):
        for obj in queryset:
            obj.delete()

models.py

1
2
3
4
class MyModel(models.Model):
    def delete(self, *args, **kwargs):
        super().delete(*args, **kwargs)
        # ...

Tips and Tricks Programming Django 4.2 Django 3.2 Django 2.2