From dc9d6739fe04ac98693d3739596ed90e36b0b525 Mon Sep 17 00:00:00 2001 From: "John R. Tipton" Date: Thu, 12 Feb 2015 15:54:59 -0500 Subject: [PATCH] - Compatibility with django-polymorphic django-polymorphic self._get_pk_value returns the class object. If this happens, we try adding _id to the pk_field. --- src/auditlog/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/auditlog/models.py b/src/auditlog/models.py index a0f409e..f72d4b3 100644 --- a/src/auditlog/models.py +++ b/src/auditlog/models.py @@ -63,7 +63,12 @@ class LogEntryManager(models.Manager): Get the primary key field value for a model instance. """ pk_field = instance._meta.pk.name - return getattr(instance, pk_field, None) + pk = getattr(instance, pk_field, None) + + # Check to make sure that we got an pk not a class object. + if hasattr(pk, '__class__'): + pk = getattr(instance, '%s_id' % pk_field, None) + return pk class LogEntry(models.Model):