mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-04-16 07:02:04 +03:00
Add multiple choice filtering example to docs
This commit is contained in:
parent
b4291e9e22
commit
95868465ef
|
@ -123,6 +123,11 @@ create your own ``FilterSet``. You can pass it directly as follows:
|
|||
class AnimalFilter(django_filters.FilterSet):
|
||||
# Do case-insensitive lookups on 'name'
|
||||
name = django_filters.CharFilter(lookup_expr=['iexact'])
|
||||
# Allow multiple genera to be selected at once
|
||||
genera = django_filters.MultipleChoiceFilter(field_name='genus',
|
||||
choices=(('Canis', 'Canis'),
|
||||
('Panthera', 'Panthera'),
|
||||
('Seahorse', 'Seahorse')))
|
||||
|
||||
class Meta:
|
||||
model = Animal
|
||||
|
@ -135,6 +140,22 @@ create your own ``FilterSet``. You can pass it directly as follows:
|
|||
all_animals = DjangoFilterConnectionField(AnimalNode,
|
||||
filterset_class=AnimalFilter)
|
||||
|
||||
|
||||
If you were interested in selecting all dogs and cats, you might query as follows:
|
||||
|
||||
.. code::
|
||||
|
||||
query {
|
||||
allAnimals(genera: ["Canis", "Panthera"]) {
|
||||
edges {
|
||||
node {
|
||||
id,
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
You can also specify the ``FilterSet`` class using the ``filterset_class``
|
||||
parameter when defining your ``DjangoObjectType``, however, this can't be used
|
||||
in unison with the ``filter_fields`` parameter:
|
||||
|
@ -162,6 +183,7 @@ in unison with the ``filter_fields`` parameter:
|
|||
animal = relay.Node.Field(AnimalNode)
|
||||
all_animals = DjangoFilterConnectionField(AnimalNode)
|
||||
|
||||
|
||||
The context argument is passed on as the `request argument <http://django-filter.readthedocs.io/en/master/guide/usage.html#request-based-filtering>`__
|
||||
in a ``django_filters.FilterSet`` instance. You can use this to customize your
|
||||
filters to be context-dependent. We could modify the ``AnimalFilter`` above to
|
||||
|
|
Loading…
Reference in New Issue
Block a user