Skip to main content

Django Duration field widget to handle duration field in the form

Project description

Django Duration Widget

This package provides a more natural way of defining duration fields in forms. It is derived from the work of Devang Padhiyar here and provides a Python2 compatible implementation.

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-durationwidget2 using pip

    pip install django-durationwidget2

  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-durationwidget2-1.0.5.tar.gz (72.0 kB view details)

Uploaded Source

Built Distribution

django_durationwidget2-1.0.5-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-durationwidget2-1.0.5.tar.gz
  • Upload date:
  • Size: 72.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for django-durationwidget2-1.0.5.tar.gz
Algorithm Hash digest
SHA256 b754af0e1a8e98ce0a351efb613cf38c300ae4e470108b5cf8ce9cc984a8449b
MD5 b766ff3430ead480baa6fe26b0bcce47
BLAKE2b-256 3d205d1e46deb730d8b07e746ccb7ca3bc415e43486b66f9bc2a63953515371a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_durationwidget2-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for django_durationwidget2-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3057ddcb3528d46ba4aff4d2053acfcd6eddc9405f587753543ce3441cf37700
MD5 22807236aaa3d1bc2c08c96a6a3ef4de
BLAKE2b-256 82c68a2f87f5e5b2fbd7ace41f4b46a449962388b4063bb153bb1b865063b092

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