šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

django-durationwidget

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

django-durationwidget

Django Duration field widget to handle duration field in the form

1.0.5
PyPI
Maintainers
1

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

  • Install django-durationwidget using pip

    pip install django-durationwidget

  • Add durationwidget to your INSTALLED_APPS setting like this::

    INSTALLED_APPS = [
        ...
        'durationwidget',
    ]
    
  • 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': {
                ...
            },
        },
    ]
    
  • 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

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts