本文整理匯總了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"))
示例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"))
示例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")
示例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"))
示例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)
示例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"})