def machine_post_save(sender, instance, created, raw, using, update_fields, **kwargs): if created: history = History( member=instance.owner, action=u"Ajout de la machine {} ({})".format(instance.name, instance.mac) ) history.save()
def member_post_save(sender, instance, created, raw, using, update_fields, **kwargs): if created: history = History( member=instance, action=u"Création" ) history.save()
def member_pre_save(sender, instance, raw, using, update_fields, **kwargs): try: before = sender.objects.get(id=instance.id) new, old = instance.compare(before) s1 = set(old.keys()) s2 = set(new.keys()) for k in s1.intersection(s2): history = History( member=instance, action=u"Modification de '{}' : '{}' en '{}'".format( sender._meta.get_field(k.replace("_id", "")).verbose_name, old[k], new[k] ) ) history.save() except sender.DoesNotExist: pass
def machine_post_delete(sender, instance, using, **kwargs): history = History( member=instance.owner, action=u"Supression de la machine {} ({})".format(instance.name, instance.mac) ) history.save()