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.

Duration

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::

    INSTALLED_APPS = [
        ...
        'durationwidget',
    ]
    
  3. Make sure to set APP_DIRS to True in settings.py

    TEMPLATES = [
        {
            '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

TimeDurationWidget

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.

Source Distribution

django-durationwidget-1.0.5.tar.gz (71.4 kB view details)

Uploaded Source

Built Distribution

django_durationwidget-1.0.5-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file django-durationwidget-1.0.5.tar.gz.

File metadata

  • Download URL: django-durationwidget-1.0.5.tar.gz
  • Upload date:
  • Size: 71.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.6

File hashes

Hashes for django-durationwidget-1.0.5.tar.gz
Algorithm Hash digest
SHA256 a77bba14c173cbfe50071ae08759ca37218acb8567639687b0119647cb78c53f
MD5 37545edfc69df6d58c7116b7921468bf
BLAKE2b-256 117a12e987f4b7ea57fb3d66997984b6863af45fd5fb326bfea47904aa27a607

See more details on using hashes here.

File details

Details for the file django_durationwidget-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: django_durationwidget-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.6

File hashes

Hashes for django_durationwidget-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7d14d5dfcf46c444fb203fe911cd058f78ba482c81ea2f0665db08369a1eff47
MD5 e2597a005b59598cc83235c0ad70a61b
BLAKE2b-256 18798e693a38b28adf374d90d4ecc6221f0a93d08442b57e699fde070c6b7780

See more details on using hashes here.

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