This is meant to be used by subclassing. The only required attribute is fields, which must be a list of fields to produce filters for. For example, given the following model definition:
class Book(models.Model):
name = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
genre = models.ForeignKey(Genre)
date_published = models.DateField()
You could create a BookFilterSet like this:
class BookFilterSet(FilterSet):
fields = [
'genre',
'authors',
'date_published',
]
The items in the fields attribute can also be two-tuples containing first the field name and second a dictionary of options to be passed to the filters as keyword arguments.
To use the BookFilterSet, please see the overview instructions. The public API of FilterSet for use consists of:
queryset must be a QuerySet, which can already be filtered.
params must be a QueryDict, normally request.GET.
This attribute contains the input QuerySet filtered according to the data in params.
In addition, there are methods that can be overridden to customise the FilterSet:
This method can be overriden to render the filterset. It is called for each field in the filterset, with the field name being passed in.
It is expected to return a Django Template instance. This template will then be rendered with the following Context data: