Commit 544c24e7 by Tom Christie

Merge pull request #3593 from tomchristie/primary-key-check-for-to-field

Proper 'primary key' checking on to_fields.
parents 95f92e99 54b79db2
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment