Skip to content

Commit

Permalink
use source instead of field_name for model field detection tfranzel#274
Browse files Browse the repository at this point in the history
  • Loading branch information
diesieben07 committed Jan 31, 2021
1 parent 5fb9c10 commit 23ca3a8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drf_spectacular/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ def _map_serializer_field(self, field, direction):
model_field = field.queryset.model._meta.pk
else:
if isinstance(field.parent, serializers.ManyRelatedField):
relation_field = field.parent.parent.Meta.model._meta.get_field(field.parent.field_name)
relation_field = field.parent.parent.Meta.model._meta.get_field(field.parent.source)
else:
relation_field = field.parent.Meta.model._meta.get_field(field.field_name)
relation_field = field.parent.Meta.model._meta.get_field(field.source)
model_field = relation_field.related_model._meta.pk

# primary keys are usually non-editable (readOnly=True) and map_model_field correctly
Expand Down

0 comments on commit 23ca3a8

Please sign in to comment.