當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。