How to change year options of django's selectDateWidget

与世无争的帅哥 提交于 2019-12-11 02:24:18

问题


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:


Pass a years argument:

lessTime = forms.DateField(required=False, 
                           widget=SelectDateWidget(years=range(1980, 2012)))


来源:https://stackoverflow.com/questions/12187671/how-to-change-year-options-of-djangos-selectdatewidget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!