mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-16 19:41:06 +03:00
Merge pull request #3593 from tomchristie/primary-key-check-for-to-field
Proper 'primary key' checking on to_fields.
This commit is contained in:
commit
544c24e7cb
|
@ -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