Django: add checksum on models

1.3k Views Asked by At

In a Django app I need to check data integrity (that is I want to detect if someone has altered the content of a record from outside the application [e.g. by changing data by hand in the DB]).

My idea is to add a "checksum" on each model instance (either an additional field on the model or on a linked "checksum" model).

So, I have two questions:

  1. Is this a good solution?
  2. Is there any django application ready for this purpose? (I didn't find anything)

Thanks

1

There are 1 best solutions below

0
Steve K On

I find it's a good solution. You could create a Checksum model with a Generic Foreign Key, then create a listener for the post_save signal, to update the Checksum of the saved object. But you'll still have to consider bulk updates within Django and change your models' default Managers to make atomic updates on querysets.

I kind of do something similar to keep track of every models with an UUID in my project.