Back To Blog Posts
Dirty Fields In Django
I recently had a software requirement in which I needed to send a notification when a model attribute changed. I looked a few third party projects, but they either did not do what I need or were not maintained, so I decided to role my own. Here is the solution, I came up with, via a Mixin:
If you want to use this, you can added a django signal to fire on Model.pre_save
and you would add some code like this:
If any model field has changed, then is_dirty
will return True
and dirty_fields
will contain the field names of the fields that were updated.