views:

23

answers:

1

I am using model forms in Django to allow the user to enter in their birthdate. I want to have the user select the date from a series of dropdown lists, one each for year, month, and day. Originally I thought that the SelectDateWidget would work. However that particular widget only displays dates in the future. I of course want to only display dates in the past.

Is there an easy way to do this? Thanks in advanced for the help.

+2  A: 

SelectDateWidget isn't only for dates in the future. If you want dates in the past, you need to pass a different years argument into your widget, otherwise it uses the current year. So within your form, just do:

SelectDateWidget(years=range(1985, datetime.date.today().year+10))

It basically accepts a list of years, and using the range function works pretty well for that.

You can see how the widget works here

Bartek
This worked perfectly, thank you very much!
SC Ghost