I found it necessary to use the seemingly-undocumented exclude argument to AuditLog() on a model that uses Django-MPTT, which adds some internal fields; not excluding them broke AuditLog(). However excluding them also breaks the object_state descriptor. Fix:
diff --git a/audit_log/models/managers.py b/audit_log/models/managers.py
index 50f3d47..4a9595d 100644
--- a/audit_log/models/managers.py
+++ b/audit_log/models/managers.py
@@ -13,8 +13,10 @@ class LogEntryObjectDescriptor(object):
self.model = model
def __get__(self, instance, owner):
- values = (getattr(instance, f.attname) for f in self.model._meta.fields)
- return self.model(*values)
+ kwargs = dict((f.attname, getattr(instance, f.attname))
+ for f in self.model._meta.fields
+ if hasattr(instance, f.attname))
+ return self.model(**kwargs)
class AuditLogManager(models.Manager):
def __init__(self, model, instance = None):
@@ -181,4 +183,4 @@ class AuditLog(object):
attrs.update(Meta = type('Meta', (), self.get_meta_options(model)))
name = '%sAuditLogEntry'%model._meta.object_name
return type(name, (models.Model,), attrs)
-
\ No newline at end of file
+
I found it necessary to use the seemingly-undocumented exclude argument to AuditLog() on a model that uses Django-MPTT, which adds some internal fields; not excluding them broke AuditLog(). However excluding them also breaks the object_state descriptor. Fix: