1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fix #17879: Corrected regression in python (inherited by yaml and json) serializer that prevented serializing model instances with null FK ref to a model when serializing with natural keys. Thanks danfairs and tmitchell.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17685 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Karen Tracey
2012-03-12 19:41:31 +00:00
parent 2f520139be
commit 20c69c5e51
4 changed files with 60 additions and 2 deletions

View File

@@ -47,7 +47,10 @@ class Serializer(base.Serializer):
def handle_fk_field(self, obj, field):
if self.use_natural_keys and hasattr(field.rel.to, 'natural_key'):
related = getattr(obj, field.name)
value = related.natural_key()
if related:
value = related.natural_key()
else:
value = None
else:
value = getattr(obj, field.get_attname())
self._current[field.name] = value