當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。