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

Proper 'primary key' checking on to_fields.
This commit is contained in:
Tom Christie 2015-11-04 14:49:11 +00:00
commit 544c24e7cb
1 changed files with 1 additions and 1 deletions

View File

@ -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