rest-filters is an extension for Django REST Framework that parses query
parameters and constructs the corresponding QuerySet
objects.
See full documentation at: https://rest-filters.readthedocs.io/
Use your favorite Python package manager to install rest-filters:
pip install rest-filters
rest-filters supports Django 4.2 and Django 5.2, with REST framework 3.14 and above.
rest-filters uses semantic versioning: https://semver.org
Here is a basic FilterSet declaration that allows filtering users by username, company, and creation date.
Check out getting started guide for more details.
from rest_filters import Filter, FilterSet
from rest_framework import serializers
class UserFilterSet(FilterSet[User]):
username = Filter(serializers.CharField(min_length=2), lookup="icontains")
company = Filter(
namespace=True,
children=[
Filter(
serializers.IntegerField(min_value=1),
lookup="id",
),
Filter(
serializers.CharField(min_length=2),
lookup="name__icontains",
param="name",
),
],
)
created = Filter(
serializers.DateTimeField(),
namespace=True,
children=[
Filter(lookup="gte"),
Filter(lookup="lte"),
],
)