Skip to content

About

Date range filter for Django admin

Topics

Resources

Stars

27 stars

Watchers

2 watching

Forks

Repository files navigation

Django admin date range filter

Test status GitHub release PyPI release Python version GitHub issues GitHub license

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.

Admin screenshot

Requirements

  • Python 3.10+
  • Django 5.2+ (5.2, 6.0 and 6.1 are tested)

Installation

Install django-daterangefilter using pip:

pip install django-daterangefilter

Add daterangefilter to INSTALLED_APPS. Example:

INSTALLED_APPS = (
    ...
    'daterangefilter',
    ...
)

Application uses static files so do not forget to issue collectstatic management command in production environment.

Example usage

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)
    ]

Advanced usage

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.

Development

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 environment

To 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.3

GitHub workflow runs the tests, publishes the package to TestPyPI and PyPI and creates GitHub release.

Credits

Filter widget uses a great JavaScript date range picker component - Date Range Picker by Dan Grossman.

About

Date range filter for Django admin

Topics

Resources

Stars

27 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages