Skip to content

Commit

Permalink
Merge pull request #2 from modsy/add-signal-data
Browse files Browse the repository at this point in the history
Include signal meta data in post_change
  • Loading branch information
msteffeck authored Jan 12, 2021
2 parents 2f6e7f9 + fcf3dfd commit 1f0af6f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions django_model_changes/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1f0af6f

Please sign in to comment.