dbd
django-bootstrap-datepicker
pypi i django-bootstrap-datepicker
dbd

django-bootstrap-datepicker

Django Widget for bootstrap-datepicker

by Paul Bucher

1.4.0 (see all)License:Apache License 2.0
pypi i django-bootstrap-datepicker
Readme

django-bootstrap-datetimepicker

This package includes a Django widget for displaying date pickers with Bootstrap 4. It uses Bootstrap datepicker widget version 1.6.4 .

Install

pip install django-bootstrap-datepicker

Make sure to add bootstrap_datepicker to your INSTALLED_APPS. Then run manage.py collectstatic to include the bootstrap-datepicker js and css files.

To-Do

General cleanup and testing

Example

forms.py

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:

You don't need to set the language option, because it will be set the current language of the thread automatically.

template.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 or django-jinja-bootstrap-form but you can draw out your HTML manually.

Requirements

  • Python >= 3.4
  • Django >= 2.0
  • Bootstrap >= 4.0
  • jquery >= 1.7.1
  • font-awesome >= 4.5.X

GitHub Stars

22

LAST COMMIT

3yrs ago

MAINTAINERS

1

CONTRIBUTORS

6

OPEN ISSUES

4

OPEN PRs

0
VersionTagPublished
1.4.0
3yrs ago
1.3.1
4yrs ago
1.3
4yrs ago
1.2.4
4yrs ago
No alternatives found
No tutorials found
Add a tutorial