mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-23 22:49:50 +03:00
use getattr to choose the pk field
This commit is contained in:
parent
7a12741524
commit
19bcc3c865
|
@ -126,8 +126,11 @@ class BaseSerializer(Field):
|
||||||
for key, val in fields.items():
|
for key, val in fields.items():
|
||||||
if key not in ret:
|
if key not in ret:
|
||||||
ret[key] = val
|
ret[key] = val
|
||||||
if val.source.primary_key:
|
try:
|
||||||
pk_field = key
|
if getattr(val.source, primary_key):
|
||||||
|
pk_field = key
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
# If 'fields' is specified, use those fields, in that order.
|
# If 'fields' is specified, use those fields, in that order.
|
||||||
if self.opts.fields:
|
if self.opts.fields:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user