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 toYYYY-MM-DD
DateTimePicker
, which defaults toYYYY-MM-DD HH:mm:ss
TimePicker
, which defaults toHH: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
- 5.0.1.0: Upgrade to Tempus Dominus full release version
5.0.1
. Fix bug for populating initial values (thank you, @ianastewart). - 0.1.2: UX enhancement: auto-dismiss dialog if the input loses focus.
- 0.1.1: Bug fixes.
- 0.1.0: Initial release.
Maintainer
- Timothy Allen (https://github.com/FlipperPA)
Contributors (Thank You!)
- Ian Stewart (https://github.com/ianastewart)
- waymou (https://github.com/waymao)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-tempus-dominus-5.0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b1ca2194253d6abb9ab776abd69d7a9385dd1f9ce50b202f99e81cf97de3fd9 |
|
MD5 | a0f9cab312ddf1a27466f87239d8c225 |
|
BLAKE2b-256 | ae32908f14b0ff634241d1609fb33989768a43313eb3a22edbe0024daf4b3f3e |
Hashes for django_tempus_dominus-5.0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07bb4a19ef7aa148a1f51eaccc3837bc27291d1d7afdc4d004c8a41bb77aaa6b |
|
MD5 | fe4f5c2edc0404e602734074b5d55091 |
|
BLAKE2b-256 | eff8126fd553b1b44f634b9a5d9971258cf84fb3e0df923756aba313fff8d32e |