Python rest_framework.mixins 模块,RetrieveModelMixin() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用rest_framework.mixins.RetrieveModelMixin()

项目:lushi8    作者:ieiayaobb    | 项目源码 | 文件源码
def retrieve(self, request, *args, **kwargs):
        chairman = Chairman(id=kwargs['id'])
        serializer = self.get_serializer(chairman)
        return Response(serializer.data)

# class ChairmanList(generics.ListAPIView):
#     queryset = Chairman.objects.all().order('-num')
#     serializer_class = ChairmanSerializer
#
#
# class ChairmanDetail(mixins.RetrieveModelMixin,
#                      generics.GenericAPIView):
#     queryset = Chairman.objects.all()
#     serializer_class = ChairmanSerializer
#     lookup_field = ('id')
#
#     def get(self, request, *args, **kwargs):
#         chairman = Chairman(id=kwargs['id'])
#         serializer = self.get_serializer(chairman)
#         return Response(serializer.data)
项目:djangocon2017viewsets    作者:buddylindsey    | 项目源码 | 文件源码
def test_attrs(self):
        self.assertIsInstance(self.view, mixins.CreateModelMixin)
        self.assertIsInstance(self.view, mixins.ListModelMixin)
        self.assertIsInstance(self.view, mixins.UpdateModelMixin)
        self.assertIsInstance(self.view, mixins.RetrieveModelMixin)
        self.assertIsInstance(self.view, mixins.DestroyModelMixin)
        self.assertIsInstance(self.view, viewsets.GenericViewSet)

        self.assertEqual(self.view.permission_classes, (IsAuthenticated,))
        self.assertEqual(self.view.serializer_class, CoinSerializer)
        self.assertSequenceEqual(
            self.view.filter_backends,
            (filters.DjangoFilterBackend, BitFilter))

        self.assertEqual(self.view.filter_class, CoinFilter)