Hide serializer field in inline serializer
See original GitHub issueHey, I’m trying to use part of serializer as a field. I know of the existence of extend_schema_serializer
and the exclude_fields
options but I cannot manage to use it as a field of a different serializer.
Example:
responses=extend_schema_serializer(many=False)(
inline_serializer(
name="getHeartBeatsResponse",
fields={
"count": serializers.IntegerField(),
"page_count": serializers.IntegerField(),
"results": serializers.ListField(child=DeviceHeartbeatSerializer()), # Here I want a exclude a field from DeviceHeartbeatSerializer
},
)
),
I tried
responses=extend_schema_serializer(many=False)(
inline_serializer(
name="getHeartBeatsResponse",
fields={
"count": serializers.IntegerField(),
"page_count": serializers.IntegerField(),
"results": serializers.ListField(
child=extend_schema_serializer(exclude_fields="device")(
DeviceHeartbeatSerializer()
)
),
},
)
),
but it does not seem to work. Does this feature simply not exist or I am I using the library in a wrong way?
Pardon me, if the answer is simply but I could not find it in the docs.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to hide field that is foreing key in serializer based on a ...
2 Answers 2 ; import Prefetch class SparkleTemplateView ; ListAPIView): serializer_class = SparkleTemplateSerializer def get_queryset ; self): user ...
Read more >HiddenField in serializers - Django REST Framework
HiddenField is a field class that does not take a value based on user input, but instead takes its value from a default...
Read more >Hiding Fields in Serializers · Issue #100 · tfranzel/drf-spectacular
I tried creating a custom serializer field (e.g. MyField ) and annotating it with @extend_schema_field(OpenApiTypes.NONE) , which does not cause ...
Read more >Serializer relations - Django REST framework
When using the ModelSerializer class, serializer fields and relationships will be automatically generated for you. Inspecting these automatically generated ...
Read more >Hide the (obvious) relation from nested serializer in DRF-django
It should be fairly obvious that the "document" field from ItemsSerializer should be derived from the parent serializer at the time of storage....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay, I can happily live with the workaround as long as I know about the limitation. Thank you very much for clarifying and helping me out!
this is the way.
i’m afraid this is a conceptual limitation. we would have 2 “different” serializer and only one name for it. unless we would attach ugly suffixes like
DeviceHeartbeat2
this cannot be resolved.