@@ -15,7 +15,7 @@ You will need to install it manually, which can be done as follows:
1515
1616 # You'll need to install django-filter
1717 pip install django-filter> =2
18-
18+
1919 After installing ``django-filter `` you'll need to add the application in the ``settings.py `` file:
2020
2121.. code :: python
@@ -290,6 +290,7 @@ Graphene provides an easy to implement filters on `ArrayField` as they are not n
290290 class Meta :
291291 model = Event
292292 interfaces = (Node,)
293+ fields = " __all__"
293294 filterset_class = EventFilterSet
294295
295296 with this set up, you can now filter events by tags:
@@ -301,3 +302,42 @@ with this set up, you can now filter events by tags:
301302 name
302303 }
303304 }
305+
306+
307+ `TypedFilter `
308+ -------------
309+
310+ Sometimes the automatic detection of the filter input type is not satisfactory for what you are trying to achieve.
311+ You can then explicitly specify the input type you want for your filter by using a `TypedFilter `:
312+
313+ .. code :: python
314+
315+ from django.db import models
316+ from django_filters import FilterSet, OrderingFilter
317+ import graphene
318+ from graphene_django.filter import TypedFilter
319+
320+ class Event (models .Model ):
321+ name = models.CharField(max_length = 50 )
322+
323+ class EventFilterSet (FilterSet ):
324+ class Meta :
325+ model = Event
326+ fields = {
327+ " name" : [" exact" , " contains" ],
328+ }
329+
330+ only_first = TypedFilter(input_type = graphene.Boolean, method = " only_first_filter" )
331+
332+ def only_first_filter (self , queryset , _name , value ):
333+ if value:
334+ return queryset[:1 ]
335+ else :
336+ return queryset
337+
338+ class EventType (DjangoObjectType ):
339+ class Meta :
340+ model = Event
341+ interfaces = (Node,)
342+ fields = " __all__"
343+ filterset_class = EventFilterSet
0 commit comments