I love the Thauber Schedule datepicker, but it\'s a datetime picker and I can\'t get it to just do dates. Any recommendations for nice looking datepickers that come with ins
Django's TextInput widget (and all of its subclasses) support specifying a type attribute to set the type of form.
You can use this to set the input type to date
(W3C specification), for example in the following way :
date = fields.DateField(widget=forms.widgets.DateInput(attrs={'type': 'date'}))
I found this quite smooth for a DateTimeField
friendly option https://github.com/asaglimbeni/django-datetime-widget
Needed to include bootstrap-timepicker css file from malot and it worked quite neatly.
Use datetime-local
as type for the input.Its not very fancy looking.But will do the Job
Hope this helps.
This is what worked for me . I am using Django 1.11 with bootstrap 3.3 .
Form.py
from django.contrib.admin.widgets import AdminDateWidget
class AddInterview(forms.ModelForm):
class Meta:
model = models.Interview
fields = ['candidate', 'date', 'position', 'question_set']
date = forms.DateField(widget=AdminDateWidget())
Template:
<form method="post">
<div class="form-group">
{% csrf_token %}
{{ form.media }}
{{ form.as_p }}
<p>Note: Date format is yyyy-mm-dd</p>
</div>
CSS: (In same above html template file)
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/forms.css' %}"/>
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/widgets.css' %}"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
JS:(In same above html template file)
<script type="text/javascript" src="/admin/jsi18n/"></script>
<script type="text/javascript" src="{% static 'admin/js/core.js' %}"></script>
<script type="text/javascript" src="{% static 'admin/js/admin/RelatedObjectLookups.js' %}"></script>
<script type="text/javascript" src="{% static 'admin/js/vendor/jquery/jquery.min.js' %}"></script>
<script type="text/javascript" src="{% static 'admin/js/jquery.init.js' %}"></script>
<script type="text/javascript" src="{% static 'admin/js/actions.min.js' %}"></script>
<script type="text/javascript" src="{% static 'admin/js/calendar.js' %}"></script>
<script type="text/javascript" src="{% static 'admin/js/admin/DateTimeShortcuts.js' %}"></script>
This is what i do to get datepicker in django forms.
install bootstrap_datepicker_plus by pip command.
pip install django-bootstrap_datepicker_plus
forms.py
from .models import Hello
from django import forms
from bootstrap_datepicker_plus import DatePickerInput
class CreateForm(forms.ModelForm):
class Meta:
model = Hello
fields =[
"Date",
]
widgets = {
'Date': DatePickerInput(),
}
settings.py
INSTALLED_APPS = [
'bootstrap_datepicker_plus',
]