Small bugfix / improvement to log_update receiver

This commit is contained in:
Jan-Jelle Kester 2013-10-23 17:10:39 +02:00
parent cc393c9611
commit ecf20dfe33

View file

@ -26,16 +26,20 @@ def log_update(sender, instance, **kwargs):
Direct use is discouraged, connect your model through auditlog.registry.registry instead.
"""
if instance.pk is not None:
old = sender.objects.get(pk=instance.pk)
new = instance
try:
old = sender.objects.get(pk=instance.pk)
except sender.DoesNotExist:
pass
else:
new = instance
changes = model_instance_diff(old, new)
changes = model_instance_diff(old, new)
log_entry = LogEntry.objects.log_create(
instance,
action=LogEntry.Action.UPDATE,
changes=json.dumps(changes),
)
log_entry = LogEntry.objects.log_create(
instance,
action=LogEntry.Action.UPDATE,
changes=json.dumps(changes),
)
def log_delete(sender, instance, **kwargs):