Python rest_framework.generics 模块,GenericAPIView() 实例源码

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

项目: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)
项目:django-rest-easy    作者:Telmediq    | 项目源码 | 文件源码
def get_serializer_name(self, verb=None):
        """
        Obtains registered serializer name for this view.

        Leverages :class:`rest_easy.registers.SerializerRegister`. Works when either of or both model
        and schema properties are available on this view.

        :return: registered serializer key.
        """
        model = getattr(self, 'model', None)
        schema = None
        if not model and not hasattr(self, 'schema') and (verb and verb not in self.serializer_schema_for_verb):
            raise RestEasyException('Either model or schema fields need to be set on a model-based GenericAPIView.')
        if verb:
            schema = self.serializer_schema_for_verb.get(verb, None)
        if schema is None:
            schema = getattr(self, 'schema', 'default')
        return serializer_register.get_name(model, schema)