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