django rest framework custom json format

class ResourceSetView(viewsets.ModelViewSet):
    queryset = models.Resources.objects.all()
    serializer_class = serializers.ResourceSerializer

    def list(self, request, *args, **kwargs):
        queryset = models.Resources.objects.all() # import
        serializer = serializers.ResourceSerializer(queryset, many=True)
        return Response({'data': serializer.data})

posted @ 2018-09-07 19:15  idlewith  阅读(132)  评论(0编辑  收藏  举报