本文整理汇总了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"})