Reputation: 570
I have found myself in a situation where for several models say X
, Y
and Z
, I would like to know when any change happens on them i.e. any create, update, delete so that I can perform another action. I have scoured the internet but all I get is libs on instance audit history. Is there any way to accomplish this inbuilt in django or even a custom solution/lib would be highly appreciated.
My idea right now is to make these models emit a post_save
signal and listen for this.
Upvotes: 0
Views: 109
Reputation: 728
Model signals are already going to be sent without your having to tell them to be, just as a part of Django models. You can set up listeners to the signals that are already being sent.
pre_delete
or post_delete
will cover your deletion case; pre_save
and post_save
will handle your update/create. post_save
sends a created
argument, which is True
if a new record was created and False
otherwise.
Upvotes: 1