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