mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 13:14:30 +03:00
Proper 'is primary key' checking
This commit is contained in:
parent
d587ad1021
commit
54b79db214
|
@ -1131,7 +1131,7 @@ class ModelSerializer(Serializer):
|
|||
field_kwargs = get_relation_kwargs(field_name, relation_info)
|
||||
|
||||
to_field = field_kwargs.pop('to_field', None)
|
||||
if to_field and to_field != 'id':
|
||||
if to_field and not relation_info.related_model._meta.get_field(to_field).primary_key:
|
||||
field_kwargs['slug_field'] = to_field
|
||||
field_class = self.serializer_related_to_field
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user