def log_update(sender, instance, **kwargs):
    """
    Signal receiver that creates a log entry when a model instance is changed and saved to the database.

    Direct use is discouraged, connect your model through :py:func:`auditlog.registry.register` instead.
    """
    if instance.pk is not None:
        try:
            old = sender.objects.get(pk=instance.pk)
        except sender.DoesNotExist:
            pass
        else:
            new = instance

            changes = model_instance_diff(old, new)

            # Log an entry only if there are changes
            if changes:
                log_entry = LogEntry.objects.log_create(
                    instance,
                    action=LogEntry.Action.UPDATE,
                    changes=json.dumps(changes),
                )
def log_update ( sender , instance , ** kwargs ) : if instance . pk is not None : try : old = sender . objects . get ( pk = instance . pk ) except sender . DoesNotExist : pass else : new = instance changes = model_instance_diff ( old , new ) if changes : log_entry = LogEntry . objects . log_create ( instance , action = LogEntry . Action . UPDATE , changes = json . dumps ( changes ) , )
Signal receiver that creates a log entry when a model instance is changed and saved to the database.

    Direct use is discouraged, connect your model through :py:func:`auditlog.registry.register` instead.