How to set attributes in html datepicker input in django

i want to use the html input date in a django forms. I already have done that.

forms.py

class DateInputPicker(forms.DateInput):
    input_type = 'date'  

class Form(forms.Form):
    date = forms.DateField(
        widget=DateInputPicker, label='Date')

But i want to add attributes like min, max and set a default value. How can i do that?

Thanks!

You can overwrite the clean function in your Form class, for example:

    def clean_date(self):
    value = timezone.now().date()
    input_date = self.cleaned_data.get("date")
    if value > input_date :
        raise forms.ValidationError(f"You can't pick this date {input_date :%d/%m/%Y}")
    return value
Back to Top