本文整理汇总了Python中django_filters.filterset.FilterSet.filter_for_field方法的典型用法代码示例。如果您正苦于以下问题:Python FilterSet.filter_for_field方法的具体用法?Python FilterSet.filter_for_field怎么用?Python FilterSet.filter_for_field使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_filters.filterset.FilterSet
的用法示例。
在下文中一共展示了FilterSet.filter_for_field方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unknown_field_type_error
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_unknown_field_type_error(self):
f = NetworkSetting._meta.get_field('mask')
with self.assertRaises(AssertionError) as excinfo:
FilterSet.filter_for_field(f, 'mask')
self.assertIn(
"FilterSet resolved field 'mask' with 'exact' lookup "
"to an unrecognized field type SubnetMaskField",
excinfo.exception.args[0])
示例2: test_field_with_choices
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_field_with_choices(self):
f = User._meta.get_field("status")
result = FilterSet.filter_for_field(f, "status")
self.assertIsInstance(result, ChoiceFilter)
self.assertEqual(result.name, "status")
self.assertTrue("choices" in result.extra)
self.assertIsNotNone(result.extra["choices"])
示例3: test_filter_for_field_with_extras
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_filter_for_field_with_extras(self):
f = User._meta.get_field('favorite_books')
result = FilterSet.filter_for_field(f, 'favorite_books')
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.name, 'favorite_books')
self.assertTrue('queryset' in result.extra)
self.assertIsNotNone(result.extra['queryset'])
示例4: test_symmetrical_selfref_m2m_field
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_symmetrical_selfref_m2m_field(self):
f = Node._meta.get_field("adjacents")
result = FilterSet.filter_for_field(f, "adjacents")
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.name, "adjacents")
self.assertTrue("queryset" in result.extra)
self.assertIsNotNone(result.extra["queryset"])
self.assertEqual(result.extra["queryset"].model, Node)
示例5: test_field_with_extras
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_field_with_extras(self):
f = User._meta.get_field("favorite_books")
result = FilterSet.filter_for_field(f, "favorite_books")
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.name, "favorite_books")
self.assertTrue("queryset" in result.extra)
self.assertIsNotNone(result.extra["queryset"])
self.assertEqual(result.extra["queryset"].model, Book)
示例6: test_filter_found_for_uuidfield
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_filter_found_for_uuidfield(self):
if UUIDTestModel is None:
self.assertLess(django.VERSION, (1, 8))
else:
f = UUIDTestModel._meta.get_field('uuid')
result = FilterSet.filter_for_field(f, 'uuid')
self.assertIsInstance(result, UUIDFilter)
self.assertEqual(result.name, 'uuid')
示例7: test_symmetrical_selfref_m2m_field
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_symmetrical_selfref_m2m_field(self):
f = Node._meta.get_field('adjacents')
result = FilterSet.filter_for_field(f, 'adjacents')
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.field_name, 'adjacents')
self.assertTrue('queryset' in result.extra)
self.assertIsNotNone(result.extra['queryset'])
self.assertEqual(result.extra['queryset'].model, Node)
示例8: test_m2m_field_with_through_model
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_m2m_field_with_through_model(self):
f = Business._meta.get_field('employees')
result = FilterSet.filter_for_field(f, 'employees')
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.name, 'employees')
self.assertTrue('queryset' in result.extra)
self.assertIsNotNone(result.extra['queryset'])
self.assertEqual(result.extra['queryset'].model, Worker)
示例9: test_reverse_m2m_relationship
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_reverse_m2m_relationship(self):
f = Book._meta.get_field('lovers')
result = FilterSet.filter_for_field(f, 'lovers')
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.field_name, 'lovers')
self.assertTrue('queryset' in result.extra)
self.assertIsNotNone(result.extra['queryset'])
self.assertEqual(result.extra['queryset'].model, User)
示例10: test_non_symmetrical_selfref_m2m_field
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_non_symmetrical_selfref_m2m_field(self):
f = DirectedNode._meta.get_field('outbound_nodes')
result = FilterSet.filter_for_field(f, 'outbound_nodes')
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.name, 'outbound_nodes')
self.assertTrue('queryset' in result.extra)
self.assertIsNotNone(result.extra['queryset'])
self.assertEqual(result.extra['queryset'].model, DirectedNode)
示例11: test_reverse_o2o_relationship
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_reverse_o2o_relationship(self):
f = Account._meta.get_field('profile')
result = FilterSet.filter_for_field(f, 'profile')
self.assertIsInstance(result, ModelChoiceFilter)
self.assertEqual(result.field_name, 'profile')
self.assertTrue('queryset' in result.extra)
self.assertIsNotNone(result.extra['queryset'])
self.assertEqual(result.extra['queryset'].model, Profile)
示例12: test_transformed_lookup_expr
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_transformed_lookup_expr(self):
f = Comment._meta.get_field('date')
result = FilterSet.filter_for_field(f, 'date', 'year__gte')
self.assertIsInstance(result, NumberFilter)
self.assertEqual(result.field_name, 'date')
示例13: test_field_that_is_subclassed
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_field_that_is_subclassed(self):
f = User._meta.get_field('first_name')
result = FilterSet.filter_for_field(f, 'first_name')
self.assertIsInstance(result, CharFilter)
示例14: test_filter_found_for_uuidfield
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_filter_found_for_uuidfield(self):
f = UUIDTestModel._meta.get_field('uuid')
result = FilterSet.filter_for_field(f, 'uuid')
self.assertIsInstance(result, UUIDFilter)
self.assertEqual(result.field_name, 'uuid')
示例15: test_filter_found_for_autofield
# 需要导入模块: from django_filters.filterset import FilterSet [as 别名]
# 或者: from django_filters.filterset.FilterSet import filter_for_field [as 别名]
def test_filter_found_for_autofield(self):
f = User._meta.get_field('id')
result = FilterSet.filter_for_field(f, 'id')
self.assertIsInstance(result, NumberFilter)
self.assertEqual(result.name, 'id')