Skip to content

Commit 80cd879

Browse files
committed
Add back extra docs
1 parent 947b5a8 commit 80cd879

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

docs/filtering.rst

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,34 @@ features of ``django-filter``. This is done by transparently creating a
107107
``django_filters.FilterSet`` class for you and passing in the values for
108108
``filter_fields``.
109109

110+
However, you may find this to be insufficient. In these cases you can
111+
create your own ``FilterSet``. You can pass it directly as follows:
112+
113+
.. code:: python
114+
115+
class AnimalNode(DjangoObjectType):
116+
class Meta:
117+
# Assume you have an Animal model defined with the following fields
118+
model = Animal
119+
filter_fields = ['name', 'genus', 'is_domesticated']
120+
interfaces = (relay.Node, )
121+
122+
123+
class AnimalFilter(django_filters.FilterSet):
124+
# Do case-insensitive lookups on 'name'
125+
name = django_filters.CharFilter(lookup_expr=['iexact'])
126+
class Meta:
127+
model = Animal
128+
fields = ['name', 'genus', 'is_domesticated']
129+
130+
131+
class Query(ObjectType):
132+
animal = relay.Node.Field(AnimalNode)
133+
# We specify our custom AnimalFilter using the filterset_class param
134+
all_animals = DjangoFilterConnectionField(AnimalNode,
135+
filterset_class=AnimalFilter)
136+
137+
110138
You can also specify the ``FilterSet`` class using the ``filterset_class``
111139
parameter when defining your ``DjangoObjectType``, however, this can't be used
112140
in unison with the ``filter_fields`` parameter:
@@ -129,8 +157,8 @@ in unison with the ``filter_fields`` parameter:
129157
class Meta:
130158
model = Animal
131159
fields = ['name', 'genus', 'is_domesticated']
132-
133-
160+
161+
134162
class AnimalNode(DjangoObjectType):
135163
class Meta:
136164
# Assume you have an Animal model defined with the following fields

0 commit comments

Comments
 (0)