@@ -123,6 +123,15 @@ create your own ``FilterSet``. You can pass it directly as follows:
123
123
class AnimalFilter (django_filters .FilterSet ):
124
124
# Do case-insensitive lookups on 'name'
125
125
name = django_filters.CharFilter(lookup_expr = [' iexact' ])
126
+ # Allow multiple genera to be selected at once
127
+ genera = django_filters.MultipleChoiceFilter(
128
+ field_name = ' genus' ,
129
+ choices = (
130
+ (' Canis' , ' Canis' ),
131
+ (' Panthera' , ' Panthera' ),
132
+ (' Seahorse' , ' Seahorse' )
133
+ )
134
+ )
126
135
127
136
class Meta :
128
137
model = Animal
@@ -135,6 +144,22 @@ create your own ``FilterSet``. You can pass it directly as follows:
135
144
all_animals = DjangoFilterConnectionField(AnimalNode,
136
145
filterset_class = AnimalFilter)
137
146
147
+
148
+ If you were interested in selecting all dogs and cats, you might query as follows:
149
+
150
+ .. code ::
151
+
152
+ query {
153
+ allAnimals(genera: ["Canis", "Panthera"]) {
154
+ edges {
155
+ node {
156
+ id,
157
+ name
158
+ }
159
+ }
160
+ }
161
+ }
162
+
138
163
You can also specify the ``FilterSet `` class using the ``filterset_class ``
139
164
parameter when defining your ``DjangoObjectType ``, however, this can't be used
140
165
in unison with the ``filter_fields `` parameter:
@@ -162,6 +187,7 @@ in unison with the ``filter_fields`` parameter:
162
187
animal = relay.Node.Field(AnimalNode)
163
188
all_animals = DjangoFilterConnectionField(AnimalNode)
164
189
190
+
165
191
The context argument is passed on as the `request argument <http://django-filter.readthedocs.io/en/master/guide/usage.html#request-based-filtering >`__
166
192
in a ``django_filters.FilterSet `` instance. You can use this to customize your
167
193
filters to be context-dependent. We could modify the ``AnimalFilter `` above to
0 commit comments