Skip to content

Commit

Permalink
Add FileField example to filter_overrides (#1680)
Browse files Browse the repository at this point in the history
  • Loading branch information
3ng7n33r authored Aug 2, 2024
1 parent 2ec1bae commit 4a3eb8b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/ref/filterset.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ This is a map of model fields to filter classes with options::
}



A possible usecase would be creating a custom filter to be able to filter on ``FileFields``
(``FileField`` filtering is hard to define in a generalised way, which is why there is no ``FileFilter``).

This example shows an override used to filter on a ``FileField``::

class Questionnaire(models.Model):
file = models.FileField(upload_to=questionnaire_path)

class QuestionnaireFilter(FilterSet):
class Meta:
model = Questionnaire
fields = ['file']
filter_overrides = {
models.FileField: {
'filter_class': CharFilter,
'extra': lambda f: {'lookup_expr': 'exact'},
},
}


.. _unknown_field_behavior:

Handling unknown fields with ``unknown_field_behavior``
Expand Down

0 comments on commit 4a3eb8b

Please sign in to comment.