python - Django: How to set DateField to only accept Today & Future dates -
i have been looking ways set django form accept dates today or days in future. have jquery datepicker on frontend, here form field modelform.
thanks help, appreciated.
date = forms.datefield( label=_("what day?"), widget=forms.textinput(), required=true)
you add clean()
method in form ensure date not in past.
import datetime class myform(forms.form): date = forms.datefield(...) def clean_date(self): date = self.cleaned_data['date'] if date < datetime.date.today(): raise forms.validationerror("the date cannot in past!") return date
see http://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-a-specific-field-attribute
Comments
Post a Comment