Skip to main content

Django Duration field widget to handle duration field in the form

Project description

Django Duration Widget

When to use?

You can find duration field as below which is not far good for humans to use.


Django duration widget is used for simplfiend Django model's Duration field.

Quick start

  1. Install django-durationwidget using pip

    pip install django-durationwidget

  2. Add durationwidget to your INSTALLED_APPS setting like this::

  3. Make sure to set APP_DIRS to True in

            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [
                os.path.join(BASE_DIR, 'templates'),
            'APP_DIRS': True,  # Setup this to True
            'OPTIONS': {
  4. Cheer up you are ready to use TimeDurationWidget as normal widget as below.

    from django import forms
    from durationwidget.widgets import TimeDurationWidget
    from .models import YourModel
    class CustomForm(forms.ModelForm):
        duration = forms.DurationField(widget=TimeDurationWidget(), required=False)
        class Meta:
            model = YourModel

It will render Duration field as below

Duration field


duration = forms.DurationField(widget=TimeDurationWidget(
    show_days=True, show_hours=True, show_minutes=True, show_seconds=True
), required=False)

Following keyword argument can be passed to show/ hide fields in duration widget.

By default all keyword arguments are set to True

show_days : To display/ hide days field in widget
show_hours : To display/ hide hours field in widget
show_minutes : To display/ hide minutes field in widget
show_seconds : To display/ hide seconds field in widget

Project details

Download files

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

Files for django-durationwidget, version 1.0.5
Filename, size File type Python version Upload date Hashes
Filename, size django_durationwidget-1.0.5-py3-none-any.whl (5.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size django-durationwidget-1.0.5.tar.gz (71.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page