I know, I can return a single object through Django viewsets for any method. But can I return multiple objects through the API? I have something like this:
class SomeViewSet(viewsets.ModelViewset):
queryset = SomeModel.objects.all()
serializer_class = SomeDataSerializer
filter_backends = [DjangoFilterBackend,]
permission_classes = (AllowAny,)
@action(methods=['GET'], detail=False, url_path='some_path')
def any_function(self, request):
queryset = self.filter_queryset(self.get_queryset())
result = any_function(args)
return Response(result, status=status.HTTP_200_OK)
Any function is defined as:
def any_function(args):
...
do something with args here and save it as result.
...
return result
This works very smoothly and I don't have any problem here. BUT can I do something like this:
def any_function(args):
result = some processing of args
next_result = another processing of args
return result, next_result
And still, get the response in the API endpoint but now for two different data. Also what if the result and next_result are two different JSON objects?