@receiver(pre_save, weak=False)<EOL>@transaction.atomic<EOL>def comparison_callback(sender, instance, **kwargs):
if validate_instance(instance) and settings.AUTOMATED_LOGGING['<STR_LIT>']:<EOL><INDENT>try:<EOL><INDENT>old = sender.objects.get(pk=instance.pk)<EOL><DEDENT>except Exception:<EOL><INDENT>return None<EOL><DEDENT>try:<EOL><INDENT>mdl = ContentType.objects.get_for_model(instance)<EOL>cur, ins = old.__dict__, instance.__dict__<EOL>old, new = {}, {}<EOL>for k in cur.keys():<EOL><INDENT>if re.match('<STR_LIT>', k):<EOL><INDENT>continue<EOL><DEDENT>changed = False<EOL>if k in ins.keys():<EOL><INDENT>if cur[k] != ins[k]:<EOL><INDENT>changed = True<EOL>new[k] = ModelObject()<EOL>new[k].value = str(ins[k])<EOL>new[k].save()<EOL>try:<EOL><INDENT>new[k].type = ContentType.objects.get_for_model(ins[k])<EOL><DEDENT>except Exception:<EOL><INDENT>logger = logging.getLogger(__name__)<EOL>logger.debug('<STR_LIT>')<EOL><DEDENT>new[k].field = Field.objects.get_or_create(name=k, model=mdl)[<NUM_LIT:0>]<EOL>new[k].save()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>changed = True<EOL><DEDENT>if changed:<EOL><INDENT>old[k] = ModelObject()<EOL>old[k].value = str(cur[k])<EOL>old[k].save()<EOL>try:<EOL><INDENT>old[k].type = ContentType.objects.get_for_model(cur[k])<EOL><DEDENT>except Exception:<EOL><INDENT>logger = logging.getLogger(__name__)<EOL>logger.debug('<STR_LIT>')<EOL><DEDENT>old[k].field = Field.objects.get_or_create(name=k, model=mdl)[<NUM_LIT:0>]<EOL>old[k].save()<EOL><DEDENT><DEDENT>if old or new:<EOL><INDENT>changelog = ModelChangelog()<EOL>changelog.save()<EOL>changelog.modification = ModelModification()<EOL>changelog.modification.save()<EOL>changelog.modification.previously.add(*old.values())<EOL>changelog.modification.currently.add(*new.values())<EOL>changelog.information = ModelObject()<EOL>changelog.information.save()<EOL>changelog.information.value = repr(instance)<EOL>changelog.information.type = ContentType.objects.get_for_model(instance)<EOL>changelog.information.save()<EOL>changelog.save()<EOL>instance.al_chl = changelog<EOL>return instance<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>print(e)<EOL>logger = logging.getLogger(__name__)<EOL>logger.warning('<STR_LIT>')<EOL><DEDENT><DEDENT>
Comparing old and new object to determin which fields changed how