3

I have some post-save signal which is trigged after the save of some model:

@receiver(signals.post_save, sender=Books)
def log_book_create_and_edit(sender, instance, **kwargs):
    if kwargs['created']:
        log_entry = AuditEvent.objects.create(
            event_type='Create',
            event_model='Book')
    else:
        log_entry = AuditEvent.objects.create(
            event_type='Create',
            event_model='Book')
    log_entry.save()

I'd like to be able to keep track of changes to the actual fields of the Book model. One way to do that is to save a serialized model instance and then use that to compare pre- and post-save states. However, is there a way to do that directly, without having to save the serialized model instance?

orange1
  • 2,871
  • 3
  • 32
  • 58
  • 1
    you can't really, you should use pre-save as described here: http://stackoverflow.com/questions/5582410/django-how-to-access-original-unmodified-instance-in-post-save-signal – ZzCalvinzZ Apr 25 '16 at 14:35

0 Answers0