From fcf3dfd384c09313b7a9393532b61b074ca17b49 Mon Sep 17 00:00:00 2001 From: Michael Steffeck Date: Mon, 11 Jan 2021 19:51:02 -0800 Subject: [PATCH] Include signal meta data in post_change --- django_model_changes/changes.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/django_model_changes/changes.py b/django_model_changes/changes.py index f13c1fe..ed81afd 100644 --- a/django_model_changes/changes.py +++ b/django_model_changes/changes.py @@ -79,7 +79,7 @@ def __init__(self, *args, **kwargs): def _state_fields(self): return [f for f in self._meta.get_fields() if f.concrete and not f.many_to_many] - def _save_state(self, new_instance=False, event_type='save'): + def _save_state(self, new_instance=False, event_type=None, created=False): # Pipe the pk on deletes so that a correct snapshot of the current # state can be taken. if event_type == DELETE: @@ -96,7 +96,8 @@ def _save_state(self, new_instance=False, event_type='save'): # Send post_change signal unless this is a new instance if not new_instance: - post_change.send(sender=self.__class__, instance=self) + post_change.send(sender=self.__class__, instance=self, + event_type=event_type, created=created) def current_state(self): """ @@ -201,8 +202,8 @@ def previous_instance(self): return self.__class__(**self.previous_state()) -def _post_save(sender, instance, **kwargs): - instance._save_state(new_instance=False, event_type=SAVE) +def _post_save(sender, instance, created, **kwargs): + instance._save_state(new_instance=False, event_type=SAVE, created=created) def _post_delete(sender, instance, **kwargs):