Skip to main content

Date range filter for Django admin

Project description

Django admin date range filter

Build Status GitHub release PyPI release Python version GitHub issues LGTM code quality LGTM code quality 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. Application supports default Django admin theme and Suit theme.

Admin screenshot

Requirements

  • Python 2.7+ or Python 3.3+
  • Django 1.9+

Installation

Install django-daterangefilter using pip:

pip install django-daterangefilter

Add daterangefilter to INSTALLED_APPS. Example:

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

Check that LANGUAGE_CODE is defined in project configuration.

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.

Credits

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-daterangefilter-0.1.2.tar.gz (8.7 kB view hashes)

Uploaded Source

Built Distribution

django_daterangefilter-0.1.2-py2.py3-none-any.whl (11.9 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page