mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-22 22:19:52 +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():
|
||||
if key not in ret:
|
||||
ret[key] = val
|
||||
if val.source.primary_key:
|
||||
pk_field = key
|
||||
try:
|
||||
if getattr(val.source, primary_key):
|
||||
pk_field = key
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# If 'fields' is specified, use those fields, in that order.
|
||||
if self.opts.fields:
|
||||
|
|
Loading…
Reference in New Issue
Block a user