Closed
Description
I'm sure I'm just doing something wrong but the documentation on working with polymorphic resources is pretty sparse so I'm not sure what to change. I have a polymorphic model Parent
with two instance types and when I try to retrieve them using DRF's ModelViewSet I get this error: Exception: Cannot get fields from a polymorphic serializer given a queryset
.
Here are my views:
from rest_framework import permissions, viewsets
from rest_framework.authentication import TokenAuthentication
from .serializers import ParentSerializer
class ParentViewSet(viewsets.ModelViewSet):
authentication_classes = (TokenAuthentication,)
included = []
pagination_class = None
permission_classes = (permissions.IsAuthenticated,)
serializer_class = ParentSerializer
And here is my serializer:
class ChildOneSerializer(serializers.ModelSerializer):
class Meta:
model = ChildOne
.
.
.
class ChildTwoSerializer(serializers.ModelSerializer):
class Meta:
model = ChildTwo
.
.
.
class ParentSerializer(PolymorphicModelSerializer):
polymorphic_serializers = [ChildOneSerializer, ChildTwoSerializer]
class Meta:
model = Parent
I have my resource_name
s defined on my models. I've tried passing a list instead of a queryset and that works for an empty response ([]
) but I run into issue #400 for non-empty responses. What should I be passing to my serializer?
Metadata
Metadata
Assignees
Labels
No labels