Django: Tracking Updates, Deletions, and Inserts
Logical Deletion
One of the features we wanted from the beginning was a default policy against deleting anything from the database. It helps with reversing mistakes and separates active data from stuff we want to keep but don’t want to see. The challenge in such a system is how to reliably keep all the objects that were soft-deleted out of our queries.
.. To track the model instance changes, we extended the queryset’s update(),delete(), create() methods as well as the model’s save() method. Anytime fields are changed through update() or save(), we generate a diff of what has changed and push it into the event database. Creation and deletion are also tracked. While it doesn’t track changes made directly in psql, it can alert us to data inconsistencies and point us to look at other logs.