Reputation: 1751
I have two serializers for two models but I want to combine those two serializers into one view
class ProductRequestView(APIView):
permission_classes = [IsAuthenticatedOrReadOnly]
def get(self, request):
city_serializer = CityCompactSerializer
models = ModelsNestedSerializer
data = {'cities':{'city data'},
'models': {'models data'}}
return Response(data, status=HTTP_200_OK)
I think I have to pass queryset to both serializers to get the data. How can I do it inside this view. I am new to DRF. Help ? Thanks
Upvotes: 1
Views: 2134
Reputation: 6933
class ProductRequestView(APIView):
permission_classes = [IsAuthenticatedOrReadOnly]
def get(self, request):
data = {
'cities': CategoryCompactSerializer(<CategoryModel>.objects.all(), many=True).data
'models': ModelsNestedSerializer(<ModelsModel>.objects.all(), many=True).data
}
return Response(data, status=HTTP_200_OK)
Upvotes: 3