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?
SelectDateWidgetisn’t only for dates in the future. If you want dates in the past, you need to pass a differentyearsargument into your widget, otherwise it uses the current year. So within your form, just do:It basically accepts a list of years, and using the
rangefunction works pretty well for that.You can see how the widget works here