Skip to content

Commit fc97282

Browse files
Add MultipleChoiceField to filtering example
1 parent 16c4b21 commit fc97282

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/filtering.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ create your own ``Filterset`` as follows:
115115
class AnimalFilter(django_filters.FilterSet):
116116
# Do case-insensitive lookups on 'name'
117117
name = django_filters.CharFilter(lookup_expr=['iexact'])
118+
# Allow multiple genera to be selected at once
119+
genera = django_filters.MultipleChoiceFilter(field_name='genus',
120+
choices=(('Canis', 'Canis'),
121+
('Panthera', 'Panthera'),
122+
('Seahorse', 'Seahorse')))
118123
119124
class Meta:
120125
model = Animal
@@ -127,6 +132,23 @@ create your own ``Filterset`` as follows:
127132
all_animals = DjangoFilterConnectionField(AnimalNode,
128133
filterset_class=AnimalFilter)
129134
135+
If you were interested in selecting all dogs and cats, you might query as follows:
136+
137+
.. code::
138+
139+
query {
140+
allAnimals(genera: ["Canis", "Panthera"]) {
141+
edges {
142+
node {
143+
id,
144+
name
145+
}
146+
}
147+
}
148+
}
149+
150+
151+
130152
The context argument is passed on as the `request argument <http://django-filter.readthedocs.io/en/master/guide/usage.html#request-based-filtering>`__
131153
in a ``django_filters.FilterSet`` instance. You can use this to customize your
132154
filters to be context-dependent. We could modify the ``AnimalFilter`` above to

0 commit comments

Comments
 (0)