Skip to content

Commit 4a3eb8b

Browse files
authored
Add FileField example to filter_overrides (carltongibson#1680)
carltongibson#1678
1 parent 2ec1bae commit 4a3eb8b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/ref/filterset.txt

+21
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,27 @@ This is a map of model fields to filter classes with options::
148148
}
149149

150150

151+
152+
A possible usecase would be creating a custom filter to be able to filter on ``FileFields``
153+
(``FileField`` filtering is hard to define in a generalised way, which is why there is no ``FileFilter``).
154+
155+
This example shows an override used to filter on a ``FileField``::
156+
157+
class Questionnaire(models.Model):
158+
file = models.FileField(upload_to=questionnaire_path)
159+
160+
class QuestionnaireFilter(FilterSet):
161+
class Meta:
162+
model = Questionnaire
163+
fields = ['file']
164+
filter_overrides = {
165+
models.FileField: {
166+
'filter_class': CharFilter,
167+
'extra': lambda f: {'lookup_expr': 'exact'},
168+
},
169+
}
170+
171+
151172
.. _unknown_field_behavior:
152173

153174
Handling unknown fields with ``unknown_field_behavior``

0 commit comments

Comments
 (0)