Application adds three Django admin list filters: DateRangeFilter, PastDateRangeFilter and FutureDateRangeFilter. These filters let user filter models by date range. PastDateRangeFilter and FutureDateRangeFilter add quick selection of predefined date ranges. Filters can be applied to any model date fields. For a field that can be empty, the picker also offers "No date", which shows the objects without a date (in the default admin theme). Application supports default Django admin theme and Suit theme.
- Python 3.10+
- Django 5.2+ (5.2, 6.0 and 6.1 are tested)
Install django-daterangefilter using pip:
pip install django-daterangefilterAdd daterangefilter to INSTALLED_APPS. Example:
INSTALLED_APPS = (
...
'daterangefilter',
...
)Application uses static files so do not forget to issue collectstatic management command in production environment.
in admin.py:
from django.contrib import admin
from daterangefilter.filters import PastDateRangeFilter, FutureDateRangeFilter
@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
list_filter = [
('created_at', PastDateRangeFilter), ('publish_at', FutureDateRangeFilter)
]Predefined ranges can be completely redefined by overriding _past_ranges.html and _future_ranges.html templates.
Take into account that these templates are inserted in the middle of the javascript code and may contain nothing but ranges
definition. For more examples on using moment library refer to library documentation.
Tests are run with tox against all supported Python and Django versions:
pip install tox
tox # all available Python versions
tox -e py313-django61 # particular environment
python runtests.py # current virtual environmentTo release a new version, update version in pyproject.toml, commit the change and push a tag
with the same version:
git tag v1.3
git push origin v1.3GitHub workflow runs the tests, publishes the package to TestPyPI and PyPI and creates GitHub release.
Filter widget uses a great JavaScript date range picker component - Date Range Picker by Dan Grossman.
