3

How to set MaxDate and MinDate of a SelectDateWidget in Django?

I am using that widget for a birthdate field.

#found in:
from django.forms.extras.widgets import SelectDateWidget
from django import forms

def someform(forms.Form):
    birthdate = forms.DateField(widget=SelectDateWidget())

So how do I change its MaxDate and MinDate? its default MinDate is this year and its MaxDate is 9 years after this year.

I want the MinDate to be maybe 100 years before this year and the Maxdate is 10 years before this year.

How do I do that?

Joseph Lafuente
  • 337
  • 3
  • 14

1 Answers1

4

You use the years= argument:

def someform(forms.Form):
    birthdate = forms.DateField(widget=SelectDateWidget(years=range(1990,2011))
Rob Osborne
  • 4,897
  • 4
  • 32
  • 43