-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Polymorphic Lists #382
Comments
hi!
that is exactly the purpose of regarding your question. if the field is readOnly this is the easiest solution: drf-spectacular/tests/test_polymorphic.py Line 122 in 1f7cf5d
for read/write, you have to subclass the field and annotate that class. a drf-spectacular/tests/test_polymorphic.py Line 98 in 1f7cf5d
sidenote: |
Hi @tfranzel, thank you for the response. The example you gave me only works when a single object is being returned, e.g.: @extend_schema_field(
PolymorphicProxySerializer(
component_name='MetaPerson',
serializers=[LegalPersonSerializer, NaturalPersonSerializer],
resource_type_field_name='type',
)
)
def get_field(self, request):
return LegalPersonSerializer(...).data. # or NaturalPersonSerializer(...).data What I want is the schema for a list of objects of varying types being returned such as below: @extend_schema_field(
PolymorphicProxySerializer(
component_name='MetaPerson',
serializers=[LegalPersonSerializer, NaturalPersonSerializer],
resource_type_field_name='type',
many=True, # <--- This doesn't work
)
)
def get_field(self, request):
return [
LegalPersonSerializer(...).data,
NaturalPersonSerializer(...).data,
...
] |
I'm looking for a solution to this problem too. For me, a |
@avere001 now i get where you are coming from. this is indeed a missing feature. now that i think of it there are ways to get good catch! i'll figure something out. |
Cool, thank you @tfranzel! |
PolymorphicProxySerializer is now derived from Serializer with certain safeguards as mocking behaviour became increasingly complicated. Now its the real thing.
please test if that fix works for you guys. cheers! |
Just tested it and it is exactly what I was looking for. I appreciate your time on this, @tfranzel! |
@avere001 , do you have a full example for the usage? I am trying to do something very similar. Spectacular part is clear, but DRF is not. |
I have tried this a few ways, but there seems to be no way to get polymorphic lists. For example, I can't find a way to document the content property of something like this:
For me, the natural thing was to annotate the field with
PolymorphicProxySerialzier(many=True, ...)
but that doesn't work.Is there any way to do this without using django-polymorphic / django-rest-polymorphic?
The text was updated successfully, but these errors were encountered: