@@ -107,6 +107,34 @@ features of ``django-filter``. This is done by transparently creating a
107
107
``django_filters.FilterSet `` class for you and passing in the values for
108
108
``filter_fields ``.
109
109
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
+
110
138
You can also specify the ``FilterSet `` class using the ``filterset_class ``
111
139
parameter when defining your ``DjangoObjectType ``, however, this can't be used
112
140
in unison with the ``filter_fields `` parameter:
@@ -129,8 +157,8 @@ in unison with the ``filter_fields`` parameter:
129
157
class Meta :
130
158
model = Animal
131
159
fields = [' name' , ' genus' , ' is_domesticated' ]
132
-
133
-
160
+
161
+
134
162
class AnimalNode (DjangoObjectType ):
135
163
class Meta :
136
164
# Assume you have an Animal model defined with the following fields
0 commit comments