Django Admin History


I am using Django Admin to create certain objects and be able to modify and monitor these objects. One thing I need is to display in Django history table is the following:

  • Changed Column
  • Old value of the changed column only
  • New value of changed column only

I tried to override the save_model function, but I couldn’t specify the old and new value of only the changed column, I was able to retrieve the whole object with the new value only.

Is there any way to do that ?

Thank you.

Best Regards,

If you review the source code for the LogEntry object, you’ll see there’s no provision in it for saving values of changed columns.

If you look at the ModelAdmin class, you’ll find methods log_addition, log_change, and log_deletion. You could write custom methods for your ModelAdmin class to write different logs. (Note, it appears that by the time you get to that point, you no longer have access to the original object. You’ll need to find some earlier point to save the changed fields - possibly in the clean method for the form.)