You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a serializer field which works differently for read and write. I used PresentablePrimaryKeyRelatedField for that.
e.g:
car_type = PresentablePrimaryKeyRelatedField(
queryset=CarType.objects.all(),
presentation_serializer=CarTypeSerializer,
read_source=None
)
This works well when accessing the api, like in request i give an integer value to car_type field and in response it gives a dictionary to car_type field. Api request-response thing worked well.
Issue is with swagger documentation. In documentation, it gives car_type as integer field in both request and response schema.
How can i deal with that?
The text was updated successfully, but these errors were encountered:
AFAIK, there is no solution for this right now. It needs to be improved.
If you are using drf-spectacular, PolymorphicProxySerializer may help. It allows you to show different serializers depending on the situation. You may define an input and output serializer and represent them differently.
I have a serializer field which works differently for read and write. I used PresentablePrimaryKeyRelatedField for that.
e.g:
car_type = PresentablePrimaryKeyRelatedField(
queryset=CarType.objects.all(),
presentation_serializer=CarTypeSerializer,
read_source=None
)
This works well when accessing the api, like in request i give an integer value to car_type field and in response it gives a dictionary to car_type field. Api request-response thing worked well.
Issue is with swagger documentation. In documentation, it gives car_type as integer field in both request and response schema.
How can i deal with that?
The text was updated successfully, but these errors were encountered: