blob: 78ac5d97a10005730e23e35e381db342cd4ceb0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# django-bootstrap-datetimepicker
This package includes a Django widget for displaying date pickers with Bootstrap 3 or Bootstrap 4. It uses [Bootstrap datepicker widget version 1.6.4 ](https://github.com/uxsolutions/bootstrap-datepicker).
## Install
pip install django-bootstrap-datepicker
## To-Do
General cleanup and testing
## Example
#### forms.py
```python
from bootstrap_datepicker.widgets import DatePicker
from django import forms
class ToDoForm(forms.Form):
todo = forms.CharField(
widget=forms.TextInput(attrs={"class": "form-control"}))
date = forms.DateField(
widget=DatePicker(
options={
"format": "mm/dd/yyyy",
"autoclose": True
}
)
)
```
The `options` will be passed to the JavaScript datepicker instance, and are documented and demonstrated here:
* [Bootstrap Datepicker Documentation](https://bootstrap-datepicker.readthedocs.org/en/stable/) (ReadTheDocs.com)
* [Interactive Demo Sandbox of All Options](https://uxsolutions.github.io/bootstrap-datepicker/)
You don't need to set the `language` option, because it will be set the current language of the thread automatically.
#### template.html
```html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="{% static 'contrib/bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'contrib/font-awesome.min.css' %}">
<script src="{% static 'contrib/bootstrap.js' %}"></script>
</head>
<body>
<form method="post" role="form">
{{ form|bootstrap }}
{% csrf_token %}
<div class="form-group">
<input type="submit" value="Submit" class="btn btn-primary" />
</div>
</form>
</body>
</html>
```
Here we assume you're using [django-bootstrap-form](https://github.com/tzangms/django-bootstrap-form) or
[django-jinja-bootstrap-form](https://github.com/samuelcolvin/django-jinja-bootstrap-form) but you can
draw out your HTML manually.
## Requirements
* Python >= 3.3
* Django >= 1.8
* Bootstrap == 4.0-alpha6
* jquery >= 1.7.1
* font-awesome >= 4.5.X
|