- 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.
This commit is contained in:
John R. Tipton 2015-02-12 15:54:59 -05:00
parent 4fd8387df0
commit dc9d6739fe

View file

@ -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):