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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-durationwidget2-1.0.6.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.6.tar.gz
Algorithm Hash digest
SHA256 269efc3cd6eec7c1da20df14938a379a0c11605a9eecf671ec8afa5956b41760
MD5 1b81448be9750a3c26416639dba948ba
BLAKE2b-256 949ae3b747493199ee38534dd84c02bd9e32f83f1c1c71ded92535af7bc90d23

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_durationwidget2-1.0.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f0b1d1f2357a5ec3e5716a7f38c7ffd8638244fd3c89b0082cca2a95bad30014
MD5 d861e6181bbee7cdfcadb89fb9e9ccbe
BLAKE2b-256 4e797ca10321e1241c12154c53d1061cbbd6c35058d1b84dfbd1ca35e532423e

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