当前位置: 首页>>代码示例>>Python>>正文


Python generics.ListAPIView方法代码示例

本文整理汇总了Python中rest_framework.generics.ListAPIView方法的典型用法代码示例。如果您正苦于以下问题:Python generics.ListAPIView方法的具体用法?Python generics.ListAPIView怎么用?Python generics.ListAPIView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rest_framework.generics的用法示例。


在下文中一共展示了generics.ListAPIView方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_model_mismatch

# 需要导入模块: from rest_framework import generics [as 别名]
# 或者: from rest_framework.generics import ListAPIView [as 别名]
def test_model_mismatch(self):
        """ cannot apply filters for one model to queryset from another """
        class FooDoc(Document):
            foo = fields.StringField()

        class BarDoc(Document):
            bar = fields.StringField()

        class FooFilter(ModelFilterset):
            class Meta:
                model = FooDoc

        class BarView(ListAPIView):
            filter_backends = (MongoFilterBackend,)
            filter_class = FooFilter
            serializer_class = mock.Mock()
            queryset = BarDoc.objects

        with self.assertRaises(TypeError):
            BarView.as_view()(APIRequestFactory().get("/?foo=Foo")) 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:22,代码来源:test_backend.py

示例2: test_model_subclassed

# 需要导入模块: from rest_framework import generics [as 别名]
# 或者: from rest_framework.generics import ListAPIView [as 别名]
def test_model_subclassed(self):
        """ can apply filters for base model to queryset of derived """
        class FooDoc(Document):
            meta = { 'allow_inheritance': True}
            foo = fields.StringField()

        class BarDoc(FooDoc):
            bar = fields.StringField()

        class FooFilter(ModelFilterset):
            class Meta:
                model = FooDoc

        class BarView(ListAPIView):
            filter_backends = (MongoFilterBackend,)
            filter_class = FooFilter
            serializer_class = mock.Mock()
            queryset = BarDoc.objects

        BarView.as_view()(APIRequestFactory().get("/?foo=Foo")) 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:22,代码来源:test_backend.py

示例3: test_view

# 需要导入模块: from rest_framework import generics [as 别名]
# 或者: from rest_framework.generics import ListAPIView [as 别名]
def test_view(self):
        class TestFilter(Filterset):
            foo = filters.CharFilter()

        class TestView(ListAPIView):
            filter_backends = (MongoFilterBackend,)
            filter_class = TestFilter
            serializer_class = mock.Mock()
            queryset = mock.Mock()

        TestView.as_view()(APIRequestFactory().get("/?foo=Foo"))
        TestView.queryset.filter.assert_called_once_with(foo="Foo") 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:14,代码来源:test_backend.py

示例4: test_unknown_class

# 需要导入模块: from rest_framework import generics [as 别名]
# 或者: from rest_framework.generics import ListAPIView [as 别名]
def test_unknown_class(self):
        """ filter_class should be our Filterset """
        class Dumb():
            pass

        class TestView(ListAPIView):
            filter_backends = (MongoFilterBackend,)
            filter_class = Dumb
            serializer_class = mock.Mock()
            queryset = mock.Mock()

        with self.assertRaises(TypeError):
            TestView.as_view()(APIRequestFactory().get("/?foo=Foo")) 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:15,代码来源:test_backend.py

示例5: post

# 需要导入模块: from rest_framework import generics [as 别名]
# 或者: from rest_framework.generics import ListAPIView [as 别名]
def post(self, request, *args, **kwargs):
        return Response({"detail": "Not allowed here"}, status=400)
        

# class UserStatusAPIView(generics.ListAPIView):
#     serializer_class            = StatusInlineUserSerializer
#     search_fields               = ('user__username', 'content')
#     #pagination_class    = CFEAPIPagination

#     def get_queryset(self, *args, **kwargs):
#         username = self.kwargs.get("username", None)
#         if username is None:
#             return Status.objects.none()
#         return Status.objects.filter(user__username=username) 
开发者ID:codingforentrepreneurs,项目名称:REST-API,代码行数:16,代码来源:views.py

示例6: test_excluding_fields

# 需要导入模块: from rest_framework import generics [as 别名]
# 或者: from rest_framework.generics import ListAPIView [as 别名]
def test_excluding_fields(self):
        @autofilter(exclude_fields=("indexed_int", "indexed_char", ))
        class SampleApiV7(ListAPIView):
            permission_classes = (AllowAny,)
            serializer_class = SampleModelForAutofilterSerializerVer1
            queryset = SampleModelForAutofilter.objects.all()

        self.assertEqual(set(SampleApiV7.filter_fields.keys()), {"id", "fk", "indexed_text", "indexed_url",
                                                                 "indexed_email", "nullable_field", "unique_text"}) 
开发者ID:HealthByRo,项目名称:drf_tweaks,代码行数:11,代码来源:test_autofilter.py


注:本文中的rest_framework.generics.ListAPIView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。