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