mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-26 11:33:44 +03:00
Merge pull request #99 from nickhudkins/feature/filter-connection-field-connections
accept connections for DjangoFilterConnectionField
This commit is contained in:
commit
a599e4cb3e
|
@ -1,6 +1,7 @@
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from ..fields import DjangoConnectionField
|
from ..fields import DjangoConnectionField
|
||||||
|
from graphene.relay import is_node
|
||||||
from .utils import get_filtering_args_from_filterset, get_filterset_class
|
from .utils import get_filtering_args_from_filterset, get_filterset_class
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,9 +10,18 @@ class DjangoFilterConnectionField(DjangoConnectionField):
|
||||||
def __init__(self, type, fields=None, extra_filter_meta=None,
|
def __init__(self, type, fields=None, extra_filter_meta=None,
|
||||||
filterset_class=None, *args, **kwargs):
|
filterset_class=None, *args, **kwargs):
|
||||||
|
|
||||||
self.fields = fields or type._meta.filter_fields
|
if is_node(type):
|
||||||
meta = dict(model=type._meta.model,
|
_fields = type._meta.filter_fields
|
||||||
fields=self.fields)
|
_model = type._meta.model
|
||||||
|
else:
|
||||||
|
# ConnectionFields can also be passed Connections,
|
||||||
|
# in which case, we need to use the Node of the connection
|
||||||
|
# to get our relevant args.
|
||||||
|
_fields = type._meta.node._meta.filter_fields
|
||||||
|
_model = type._meta.node._meta.model
|
||||||
|
|
||||||
|
self.fields = fields or _fields
|
||||||
|
meta = dict(model=_model, fields=self.fields)
|
||||||
if extra_filter_meta:
|
if extra_filter_meta:
|
||||||
meta.update(extra_filter_meta)
|
meta.update(extra_filter_meta)
|
||||||
self.filterset_class = get_filterset_class(filterset_class, **meta)
|
self.filterset_class = get_filterset_class(filterset_class, **meta)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user