5👍
✅
Yes it’s possible. Have a look at the docs here and the example below.
class CommentForm(forms.Form):
name = forms.DateField(widget=forms.DateField(attrs={'min': '2020-01-01', 'max': '2021-01-01'}))
Or in the __init__
:
self.fields['name'].widget.attrs.update({'min': '2020-01-01', 'max': '2021-01-01'})
You might want to use a datepicker made by someone else since the HTML5 datepicker might not show on IE or Safari.
Source:stackexchange.com