Skip to content

Commit

Permalink
Improve handling of serializers.ManyRelatedField
Browse files Browse the repository at this point in the history
Related to tfranzel#79
  • Loading branch information
jayvdb committed Jun 6, 2020
1 parent bed451c commit 8006446
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drf_spectacular/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,13 @@ def _map_serializer_field(self, field, direction):
# to hit the database.
if getattr(field, 'queryset', None) is not None:
schema = self._map_model_field(field.queryset.model._meta.pk, direction)
else:
elif hasattr(field.parent, 'Meta'):
schema = self._map_model_field(field.parent.Meta.model._meta.pk, direction)
elif isinstance(field.parent, serializers.ManyRelatedField):
schema = build_array_type(build_object_type())
else:
schema = build_basic_type(OpenApiTypes.STR)

# primary keys are usually non-editable (readOnly=True) and map_model_field correctly
# signals that attribute. however this does not apply in the context of relations.
schema.pop('readOnly', None)
Expand Down

0 comments on commit 8006446

Please sign in to comment.