Python django_filters 模块,FilterSet() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django_filters.FilterSet()

项目:graphene-django    作者:graphql-python    | 项目源码 | 文件源码
def test_global_id_field_explicit():
    class ArticleIdFilter(django_filters.FilterSet):

        class Meta:
            model = Article
            fields = ['id']

    field = DjangoFilterConnectionField(ArticleNode, filterset_class=ArticleIdFilter)
    filterset_class = field.filterset_class
    id_filter = filterset_class.base_filters['id']
    assert isinstance(id_filter, GlobalIDFilter)
    assert id_filter.field_class == GlobalIDFormField
项目:graphene-django    作者:graphql-python    | 项目源码 | 文件源码
def test_filterset_descriptions():
    class ArticleIdFilter(django_filters.FilterSet):

        class Meta:
            model = Article
            fields = ['id']

        max_time = django_filters.NumberFilter(method='filter_max_time', label="The maximum time")

    field = DjangoFilterConnectionField(ArticleNode, filterset_class=ArticleIdFilter)
    max_time = field.args['max_time']
    assert isinstance(max_time, Argument)
    assert max_time.type == Float
    assert max_time.description == 'The maximum time'
项目:graphene-django    作者:graphql-python    | 项目源码 | 文件源码
def test_global_id_multiple_field_explicit():
    class ReporterPetsFilter(django_filters.FilterSet):

        class Meta:
            model = Reporter
            fields = ['pets']

    field = DjangoFilterConnectionField(ReporterNode, filterset_class=ReporterPetsFilter)
    filterset_class = field.filterset_class
    multiple_filter = filterset_class.base_filters['pets']
    assert isinstance(multiple_filter, GlobalIDMultipleChoiceFilter)
    assert multiple_filter.field_class == GlobalIDMultipleChoiceField
项目:graphene-django    作者:graphql-python    | 项目源码 | 文件源码
def test_global_id_multiple_field_explicit_reverse():
    class ReporterPetsFilter(django_filters.FilterSet):

        class Meta:
            model = Reporter
            fields = ['articles']

    field = DjangoFilterConnectionField(ReporterNode, filterset_class=ReporterPetsFilter)
    filterset_class = field.filterset_class
    multiple_filter = filterset_class.base_filters['articles']
    assert isinstance(multiple_filter, GlobalIDMultipleChoiceFilter)
    assert multiple_filter.field_class == GlobalIDMultipleChoiceField
项目:adhocracy4    作者:liqd    | 项目源码 | 文件源码
def test_free_text_filter_exception():
    with pytest.raises(ImproperlyConfigured):
        class SearchFilterSet(django_filters.FilterSet):

            search = FreeTextFilter(
                # no fields set
            )

            class Meta:
                model = question_models.Question
                fields = ['search']