class PromiseForm(ModelForm):
class Meta:
model = Promise
fields = ['title', 'description', 'made_on']
widgets = {
'made_on': DateInput(attrs={'type': 'date'}),
}
pip install django-bootstrap-datepicker-plus
# Directly from GCBV with no dependencies.
# Alternatively, you could also override the widget in a separate Form object.
from django.views.generic import CreateView
from django.contrib.admin.widgets import AdminDateWidget
from .models import MyModel
class MyModelCreateView(CreateView):
template_name = 'form.html'
model = MyModel
fields = ['date_field', ...]
def get_form(self, form_class=None):
form = super(MyModelCreateView, self).get_form(form_class)
form.fields['date_field'].widget = AdminDateWidget(attrs={'type': 'date'})
return form
INSTALLED_APPS = [
'bootstrap_datepicker_plus',
]