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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user