Skip to main content

A Django widget for the Tempus Dominus Bootstrap 4 DateTime picker.

Project description

Django Tempus Dominus

Django Tempus Dominus provides Django widgets for the Tempus Dominus Bootstrap 4 DateTime date and time picker. Why yet another date and time picker for Django? None supported the Tempus Dominus date and time picker, which is actively developed and feature rich. It is a successor to the popular bootstrap-datetimepicker JavaScript library.

Installation

  • From PyPI: pip install django-tempus-dominus

  • From source:

git clone git+https://github.com/FlipperPA/django-tempus-dominus.git
pip install -e django-tempus-dominus

Usage

Three widgets are provided:

  • DatePicker, which defaults to YYYY-MM-DD
  • DateTimePicker, which defaults to YYYY-MM-DD HH:mm:ss
  • TimePicker, which defaults to HH:mm:ss

In your Django form, you can use the widgets like this:

import datetime

from django import forms
from tempus_dominus.widgets import DatePicker, TimePicker, DateTimePicker

class MyForm(forms.Form):
    date_field = forms.DateField(
        required=True,
        widget=DatePicker(
            options={
                'minDate': '2009-01-20',
                'maxDate': '2017-01-20',
            }
        ),
    )
    time_field = forms.TimeField(
        widget=TimePicker(
            options={
                'enabledHours': [9, 10, 11, 12, 13, 14, 15, 16],
            }
        ),
    )
    datetime_field = forms.DateTimeField(
        widget=DateTimePicker(
            options={
                'minDate': (datetime.date.today() + datetime.timedelta(days=1)).strftime('%Y-%m-%d'),  # Tomorrow
                'useCurrent': True,
                'collapse': False,
            }
        ),
    )

The options dictionary will be passed to Tempus Dominus. A full list of options is available here.

Then in your template, include jQuery, {{ form.media }}, and render the form:

<html>
    <head>
        <script crossorigin="anonymous" integrity="sha384-xBuQ/xzmlsLoJpyjoggmTEz8OWUFM0/RC5BsqQBDX2v5cMvDHcMakNTNrHIW2I5f" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
        {{ form.media }}
    </head>
<body>
    <form method="post" action=".">
        {% csrf_token %}
        {{ form.as_p }}
    </form>
</body>
</html>

Change Log

  • 0.1.2: UX enhancement: auto-dismiss dialog if the input loses focus.
  • 0.1.1: Bug fixes.
  • 0.1.0: Initial release.

Maintainer

Contributors (Thank You!)

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-tempus-dominus-0.1.2.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

django_tempus_dominus-0.1.2-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file django-tempus-dominus-0.1.2.tar.gz.

File metadata

File hashes

Hashes for django-tempus-dominus-0.1.2.tar.gz
Algorithm Hash digest
SHA256 83b5c711cd27061e080ae192cb7445827fa59345a68ff419e3c97da9094b6afc
MD5 b30147096896e4cb2b72dc43bb0bfe73
BLAKE2b-256 39f3ec63abcddd7959d6e1e9b028e8713dd7b42164812d29e06e858a03339a70

See more details on using hashes here.

File details

Details for the file django_tempus_dominus-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_tempus_dominus-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a7b2a1fada7816a885243a599c9980049ebd926c57dbcebd919d05e2616d7c2a
MD5 eb8a31ea3dda5e9cf1cbab4e6c391d3c
BLAKE2b-256 2848f8f25477c7c05c39160f0bc9a35d71b52f3a313c2de22158729ec7ec3167

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