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 https://github.com/FlipperPA/django-tempus-dominus.git
pip install -e django-tempus-dominus
Add tempus_dominus
to INSTALLED_APPS
in your Django settings.
Usage & Settings
The following settings are available:
TEMPUS_DOMINUS_LOCALIZE
(default:False
): ifTrue
, widgets will be translated to the selected browser language and use the localized date and time formats.TEMPUS_DOMINUS_INCLUDE_ASSETS
(default:True
): ifTrue
, loads Tempus Dominus andmoment
JS and CSS from Cloudflare's CDN, otherwise loading the JS and CSS are up to you.
Three widgets are provided:
DatePicker
- Defaults to
YYYY-MM-DD
- Defaults to
L
ifTEMPUS_DOMINUS_LOCALIZE
isTrue
- Defaults to
DateTimePicker
- Defaults to
YYYY-MM-DD HH:mm:ss
- Defaults to
L LTS
ifTEMPUS_DOMINUS_LOCALIZE
isTrue
- Defaults to
TimePicker
- Defaults to
HH:mm:ss
- Defaults to
LTS
ifTEMPUS_DOMINUS_LOCALIZE
isTrue
- Defaults to
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(widget=DatePicker())
date_field_required_with_min_max_date = 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.3: Add setting to exclude CDN CSS and JS assets. Add initial test suite.
- 5.0.1.2: Documentation clean up.
- 5.0.1.1: Option to l10n and i18n to all pickers.
- 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 & DjangoCon US Sprinters (Thank You!)
- Bryan Collazo (https://github.com/bcollazo)
- Donna St. Louis (https://github.com/dcstlouis)
- Ian Stewart (https://github.com/ianastewart)
- Jake Bell (https://github.com/theunraveler)
- John Carroll (https://github.com/johnnyporkchops)
- Katherine Dey (https://github.com/deyspring)
- Kenneth Love (https://github.com/kennethlove)
- Kevan Swanberg (https://github.com/kevswanberg)
- Ryan Sullivan (https://github.com/rgs258)
- Tiffany Huang (https://github.com/tiff8433)
- Václav 'ax' Hůla (https://github.com/AxTheB)
- 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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef883238cf1a924f0f21e286b342228ca5e775eb7b3504a5e1a9e9d20c7eb9a0 |
|
MD5 | c2ecb10fa10fd5b8cac922b6b1b6fba1 |
|
BLAKE2b-256 | 4ecd13c01e646e1768a10385e143adb48da57ffb26b80202f5a46425a2946734 |
Hashes for django_tempus_dominus-5.0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ec27277c5a3e0318f0d3e31e46e44cf3772c44c4593e83e211683cc736e4890 |
|
MD5 | 4ca6b4e295877ceb989d501790cc52fa |
|
BLAKE2b-256 | ff1b11e19a5e29cef4e5881395a2bf43192ddedb78267f91776ff69f48b0abe2 |