本文整理汇总了Python中django_filters.filterset.FilterSet类的典型用法代码示例。如果您正苦于以下问题:Python FilterSet类的具体用法?Python FilterSet怎么用?Python FilterSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FilterSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unknown_field_type_error
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_filter_for_field_with_extras
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'])
示例3: test_field_with_choices
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"])
示例4: test_reverse_m2m_field_with_through_model
def test_reverse_m2m_field_with_through_model(self):
f = Worker._meta.get_field("employers")
result = FilterSet.filter_for_reverse_field(f, "employers")
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.name, "employers")
self.assertTrue("queryset" in result.extra)
self.assertIsNotNone(result.extra["queryset"])
self.assertEqual(result.extra["queryset"].model, Business)
示例5: test_reverse_m2m_relationship
def test_reverse_m2m_relationship(self):
f = Book._meta.get_field("lovers")
result = FilterSet.filter_for_reverse_field(f, "lovers")
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.name, "lovers")
self.assertTrue("queryset" in result.extra)
self.assertIsNotNone(result.extra["queryset"])
self.assertEqual(result.extra["queryset"].model, User)
示例6: test_reverse_o2o_relationship
def test_reverse_o2o_relationship(self):
f = Account._meta.get_field("profile")
result = FilterSet.filter_for_reverse_field(f, "profile")
self.assertIsInstance(result, ModelChoiceFilter)
self.assertEqual(result.name, "profile")
self.assertTrue("queryset" in result.extra)
self.assertIsNotNone(result.extra["queryset"])
self.assertEqual(result.extra["queryset"].model, Profile)
示例7: test_non_symmetrical_selfref_m2m_field
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)
示例8: test_field_with_extras
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)
示例9: test_filter_found_for_uuidfield
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')
示例10: test_reverse_m2m_field_with_through_model
def test_reverse_m2m_field_with_through_model(self):
f = Worker._meta.get_field_by_name('employers')[0]
result = FilterSet.filter_for_reverse_field(f, 'employers')
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.name, 'employers')
self.assertTrue('queryset' in result.extra)
self.assertIsNotNone(result.extra['queryset'])
self.assertEqual(result.extra['queryset'].model, Business)
示例11: test_reverse_fk_relationship
def test_reverse_fk_relationship(self):
f = User._meta.get_field_by_name("comments")[0]
result = FilterSet.filter_for_reverse_field(f, "comments")
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.name, "comments")
self.assertTrue("queryset" in result.extra)
self.assertIsNotNone(result.extra["queryset"])
self.assertEqual(result.extra["queryset"].model, Comment)
示例12: test_reverse_m2m_relationship
def test_reverse_m2m_relationship(self):
f = Book._meta.get_field_by_name('lovers')[0]
result = FilterSet.filter_for_reverse_field(f, 'lovers')
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.name, 'lovers')
self.assertTrue('queryset' in result.extra)
self.assertIsNotNone(result.extra['queryset'])
self.assertEqual(result.extra['queryset'].model, User)
示例13: test_reverse_non_symmetrical_selfref_m2m_field
def test_reverse_non_symmetrical_selfref_m2m_field(self):
f = DirectedNode._meta.get_field_by_name('inbound_nodes')[0]
result = FilterSet.filter_for_reverse_field(f, 'inbound_nodes')
self.assertIsInstance(result, ModelMultipleChoiceFilter)
self.assertEqual(result.name, 'inbound_nodes')
self.assertTrue('queryset' in result.extra)
self.assertIsNotNone(result.extra['queryset'])
self.assertEqual(result.extra['queryset'].model, DirectedNode)
示例14: test_symmetrical_selfref_m2m_field
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)
示例15: test_reverse_o2o_relationship
def test_reverse_o2o_relationship(self):
f = Account._meta.get_field_by_name('profile')[0]
result = FilterSet.filter_for_reverse_field(f, 'profile')
self.assertIsInstance(result, ModelChoiceFilter)
self.assertEqual(result.name, 'profile')
self.assertTrue('queryset' in result.extra)
self.assertIsNotNone(result.extra['queryset'])
self.assertEqual(result.extra['queryset'].model, Profile)