@@ -123,6 +123,15 @@ create your own ``FilterSet``. You can pass it directly as follows:
123123 class AnimalFilter (django_filters .FilterSet ):
124124 # Do case-insensitive lookups on 'name'
125125 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+ )
126135
127136 class Meta :
128137 model = Animal
@@ -135,6 +144,22 @@ create your own ``FilterSet``. You can pass it directly as follows:
135144 all_animals = DjangoFilterConnectionField(AnimalNode,
136145 filterset_class = AnimalFilter)
137146
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+
138163 You can also specify the ``FilterSet `` class using the ``filterset_class ``
139164parameter when defining your ``DjangoObjectType ``, however, this can't be used
140165in unison with the ``filter_fields `` parameter:
@@ -162,6 +187,7 @@ in unison with the ``filter_fields`` parameter:
162187 animal = relay.Node.Field(AnimalNode)
163188 all_animals = DjangoFilterConnectionField(AnimalNode)
164189
190+
165191 The context argument is passed on as the `request argument <http://django-filter.readthedocs.io/en/master/guide/usage.html#request-based-filtering >`__
166192in a ``django_filters.FilterSet `` instance. You can use this to customize your
167193filters to be context-dependent. We could modify the ``AnimalFilter `` above to
0 commit comments