本文整理匯總了Python中graphene_django.filter.DjangoFilterConnectionField方法的典型用法代碼示例。如果您正苦於以下問題:Python filter.DjangoFilterConnectionField方法的具體用法?Python filter.DjangoFilterConnectionField怎麽用?Python filter.DjangoFilterConnectionField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類graphene_django.filter
的用法示例。
在下文中一共展示了filter.DjangoFilterConnectionField方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: connection_resolver
# 需要導入模塊: from graphene_django import filter [as 別名]
# 或者: from graphene_django.filter import DjangoFilterConnectionField [as 別名]
def connection_resolver(
cls, resolver, connection, default_manager,
max_limit, enforce_first_or_last, filterset_class,
filtering_args, root, info, **args
):
filter_kwargs = {k: v for k, v in args.items() if k in filtering_args}
qs = filterset_class(
data=filter_kwargs,
queryset=default_manager.get_queryset()
).qs
if not cls.has_permission(info):
return super(DjangoFilterConnectionField, cls).connection_resolver(
resolver, connection, qs.none(), max_limit, enforce_first_or_last,
root, info, **args,
)
return super(DjangoFilterConnectionField, cls).connection_resolver(
resolver, connection, qs, max_limit, enforce_first_or_last,
filterset_class, filtering_args, **args,
)
示例2: CollectionFilterSetFactory
# 需要導入模塊: from graphene_django import filter [as 別名]
# 或者: from graphene_django.filter import DjangoFilterConnectionField [as 別名]
def CollectionFilterSetFactory(filterset_class, orderset_class=None):
"""
Build single-filter filterset classes.
Use this in place of a regular filterset_class parametrisation in
the serializers.
If you pass the optional `orderset_class` parameter, it is used for
an `order` filter. The filters defined in the `orderset_class` must
inherit from `caluma.caluma_core.ordering.CalumaOrdering` and provide a
`get_ordering_value()` method.
Example:
>>> all_documents = DjangoFilterConnectionField(
... Document, filterset_class=CollectionFilterSetFactory(DocumentFilterSet)
... )
"""
suffix = "" if orderset_class else "NoOrdering"
cache_key = filterset_class.__name__ + suffix
if cache_key in CollectionFilterSetFactory._cache:
return CollectionFilterSetFactory._cache[cache_key]
coll_fields = {"filter": FilterCollectionFactory(filterset_class, ordering=False)}
if orderset_class:
coll_fields["order"] = FilterCollectionFactory(orderset_class, ordering=True)
ret = CollectionFilterSetFactory._cache[cache_key] = type(
f"{filterset_class.__name__}Collection",
(filterset_class, FilterSet),
{
**coll_fields,
"Meta": type(
"Meta",
(filterset_class.Meta,),
{
"model": filterset_class.Meta.model,
"fields": filterset_class.Meta.fields + tuple(coll_fields.keys()),
},
),
},
)
return ret