Skip to content

Commit 544c24e

Browse files
committed
Merge pull request #3593 from tomchristie/primary-key-check-for-to-field
Proper 'primary key' checking on to_fields.
2 parents 95f92e9 + 54b79db commit 544c24e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

rest_framework/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ def build_relational_field(self, field_name, relation_info):
11311131
field_kwargs = get_relation_kwargs(field_name, relation_info)
11321132

11331133
to_field = field_kwargs.pop('to_field', None)
1134-
if to_field and to_field != 'id':
1134+
if to_field and not relation_info.related_model._meta.get_field(to_field).primary_key:
11351135
field_kwargs['slug_field'] = to_field
11361136
field_class = self.serializer_related_to_field
11371137

0 commit comments

Comments
 (0)