django admin save/delete override

Hello,

As the title indicates, I’d like to be able to modify Django’s internal methods to save or delete an object from the admin.

I develop a history function and for that I would also like to increment the changes made from the administration panel.

I saw that I could modify the ModelAdmin save_model and delete_model methods in an admin.py file but it doesn’t work.

I tried to add in the admin.py file of my main application:

from django.contrib import admin

class ArticleAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        obj.username = request.user
        super().save_model(request, obj, form, change)
        print("SAVE MODEL DETECTED")


    def delete_model(self, request, obj):
        super().delete_model(request, obj)
        print("DELETE MODEL DETECTED")

Then i tried to modify and delete objects of my database from the Django admin page but the print() don’t work…
I’m surely doing it wrong but i can’t find help on forums so maybe someone can explain me how it works exactly ?

Thanks in advance

Are you deleting the objects from the ArticleAdmin list view page (as an admin action) or the details page? (They’re two different pages.) Or are these being included in another model’s page as an inline and you’re editing them in that other page?

I’ve never done anything like this, so I have no knowledge that can directly help. I’m just trying to identify possibilities to explain why these methods aren’t being executed.

I might also try adding prints before the super to see if super is going somewhere else…