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


Python django_filters.FilterSet方法代码示例

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


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

示例1: test_free_text_filter_exception

# 需要导入模块: import django_filters [as 别名]
# 或者: from django_filters import FilterSet [as 别名]
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'] 
开发者ID:liqd,项目名称:adhocracy4,代码行数:13,代码来源:test_free_text_filter.py

示例2: test_filter_filterset_class_filter_fields_exception

# 需要导入模块: import django_filters [as 别名]
# 或者: from django_filters import FilterSet [as 别名]
def test_filter_filterset_class_filter_fields_exception():
    with pytest.raises(Exception):

        class ReporterFilter(FilterSet):
            class Meta:
                model = Reporter
                fields = ["first_name", "articles"]

        class ReporterFilterNode(DjangoObjectType):
            class Meta:
                model = Reporter
                interfaces = (Node,)
                filterset_class = ReporterFilter
                filter_fields = ["first_name", "articles"] 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:16,代码来源:test_fields.py

示例3: test_filter_filterset_class_information_on_meta

# 需要导入模块: import django_filters [as 别名]
# 或者: from django_filters import FilterSet [as 别名]
def test_filter_filterset_class_information_on_meta():
    class ReporterFilter(FilterSet):
        class Meta:
            model = Reporter
            fields = ["first_name", "articles"]

    class ReporterFilterNode(DjangoObjectType):
        class Meta:
            model = Reporter
            interfaces = (Node,)
            filterset_class = ReporterFilter

    field = DjangoFilterConnectionField(ReporterFilterNode)
    assert_arguments(field, "first_name", "articles")
    assert_not_orderable(field) 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:17,代码来源:test_fields.py

示例4: test_filter_filterset_class_information_on_meta_related

# 需要导入模块: import django_filters [as 别名]
# 或者: from django_filters import FilterSet [as 别名]
def test_filter_filterset_class_information_on_meta_related():
    class ReporterFilter(FilterSet):
        class Meta:
            model = Reporter
            fields = ["first_name", "articles"]

    class ArticleFilter(FilterSet):
        class Meta:
            model = Article
            fields = ["headline", "reporter"]

    class ReporterFilterNode(DjangoObjectType):
        class Meta:
            model = Reporter
            interfaces = (Node,)
            filterset_class = ReporterFilter

    class ArticleFilterNode(DjangoObjectType):
        class Meta:
            model = Article
            interfaces = (Node,)
            filterset_class = ArticleFilter

    class Query(ObjectType):
        all_reporters = DjangoFilterConnectionField(ReporterFilterNode)
        all_articles = DjangoFilterConnectionField(ArticleFilterNode)
        reporter = Field(ReporterFilterNode)
        article = Field(ArticleFilterNode)

    schema = Schema(query=Query)
    articles_field = ReporterFilterNode._meta.fields["articles"].get_type()
    assert_arguments(articles_field, "headline", "reporter")
    assert_not_orderable(articles_field) 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:35,代码来源:test_fields.py

示例5: test_global_id_field_explicit

# 需要导入模块: import django_filters [as 别名]
# 或者: from django_filters import FilterSet [as 别名]
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 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:13,代码来源:test_fields.py

示例6: test_global_id_multiple_field_explicit

# 需要导入模块: import django_filters [as 别名]
# 或者: from django_filters import FilterSet [as 别名]
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 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:15,代码来源:test_fields.py

示例7: test_global_id_multiple_field_explicit_reverse

# 需要导入模块: import django_filters [as 别名]
# 或者: from django_filters import FilterSet [as 别名]
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 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:15,代码来源:test_fields.py

示例8: test_filter_shortcut_filterset_context

# 需要导入模块: import django_filters [as 别名]
# 或者: from django_filters import FilterSet [as 别名]
def test_filter_shortcut_filterset_context():
    class ArticleContextFilter(django_filters.FilterSet):
        class Meta:
            model = Article
            exclude = set()

        @property
        def qs(self):
            qs = super(ArticleContextFilter, self).qs
            return qs.filter(reporter=self.request.reporter)

    class Query(ObjectType):
        context_articles = DjangoFilterConnectionField(
            ArticleNode, filterset_class=ArticleContextFilter
        )

    r1 = Reporter.objects.create(first_name="r1", last_name="r1", email="r1@test.com")
    r2 = Reporter.objects.create(first_name="r2", last_name="r2", email="r2@test.com")
    Article.objects.create(
        headline="a1",
        pub_date=datetime.now(),
        pub_date_time=datetime.now(),
        reporter=r1,
        editor=r1,
    )
    Article.objects.create(
        headline="a2",
        pub_date=datetime.now(),
        pub_date_time=datetime.now(),
        reporter=r2,
        editor=r2,
    )

    class context(object):
        reporter = r2

    query = """
    query {
        contextArticles {
            edges {
                node {
                    headline
                }
            }
        }
    }
    """
    schema = Schema(query=Query)
    result = schema.execute(query, context_value=context())
    assert not result.errors

    assert len(result.data["contextArticles"]["edges"]) == 1
    assert result.data["contextArticles"]["edges"][0]["node"]["headline"] == "a2" 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:55,代码来源:test_fields.py


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