How to change year options of django's selectD

2019-07-14 04:59发布

I want to use django's selectDateWidget for a form but the options for years are from 2012-2021. I need to display past years and probably up to 1980. How can I modify selectDateWidget?

lessTime = forms.DateField(required=False, widget=SelectDateWidget())

1条回答
欢心
2楼-- · 2019-07-14 05:34

Pass a years argument:

lessTime = forms.DateField(required=False, 
                           widget=SelectDateWidget(years=range(1980, 2012)))
查看更多
登录 后发表回答