diff --git a/docs/filtering.rst b/docs/filtering.rst index cab61ec..584c0a4 100644 --- a/docs/filtering.rst +++ b/docs/filtering.rst @@ -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 `__ 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