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


Python filters.SearchFilter方法代码示例

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


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

示例1: test_viewset_factory

# 需要导入模块: from rest_framework import filters [as 别名]
# 或者: from rest_framework.filters import SearchFilter [as 别名]
def test_viewset_factory(self):
        viewset = self.endpoint.get_viewset()
        self.assertEqual(viewset.serializer_class, self.endpoint.get_serializer())

        for backend in (DjangoFilterBackend, filters.SearchFilter):
            self.assertNotIn(backend, viewset.filter_backends)

        self.assertEqual(viewset.__name__, 'ProductViewSet')

        viewset = self.alternate_endpoint.get_viewset()

        for attr in ('permission_classes', 'filter_fields', 'search_fields', 'ordering_fields'):
            self.assertEqual(list(getattr(viewset, attr)), list(getattr(self, attr)))

        for backend in ('DjangoFilterBackend', 'SearchFilter', 'OrderingFilter'):
            self.assertIn(backend, [be.__name__ for be in viewset.filter_backends])

        self.assertEqual(viewset.pagination_class.__name__, 'ProductPagination')
        self.assertTrue(issubclass(
            viewset.pagination_class,
            pagination.PageNumberPagination
        )) 
开发者ID:drf-forms,项目名称:drf-schema-adapter,代码行数:24,代码来源:test_unit.py

示例2: test_inheritance

# 需要导入模块: from rest_framework import filters [as 别名]
# 或者: from rest_framework.filters import SearchFilter [as 别名]
def test_inheritance(self):

        class DummyEndpoint(Endpoint):
            model = Product
            permission_classes = self.permission_classes
            filter_fields = self.filter_fields
            search_fields = self.search_fields
            ordering_fields = self.ordering_fields

        endpoint = DummyEndpoint()

        self.assertEqual(endpoint.model, Product)
        self.assertEqual(len(endpoint.get_fields_for_serializer()), len(self.fields) + 1)
        for field in self.fields:
            self.assertIn(field, endpoint.get_fields_for_serializer())
        self.assertIn('__str__', endpoint.get_fields_for_serializer())

        serializer = endpoint.get_serializer()
        self.assertEqual(serializer.Meta.model, Product)
        self.assertEqual(len(serializer().fields.items()), len(self.endpoint.get_fields_for_serializer()))

        viewset = endpoint.get_viewset()

        for attr in ('permission_classes', 'filter_fields', 'search_fields', 'ordering_fields'):
            self.assertEqual(list(getattr(viewset, attr)), list(getattr(self, attr)))

        for backend in ('DjangoFilterBackend', 'SearchFilter', 'OrderingFilter'):
            self.assertIn(backend, [be.__name__ for be in viewset.filter_backends]) 
开发者ID:drf-forms,项目名称:drf-schema-adapter,代码行数:30,代码来源:test_unit.py


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