开发者

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

开发者 https://www.devze.com 2023-03-31 13:48 出处:网络
How to set MaxDate and MinDate of a SelectDateWidget in Django? I am using that widget for a birthdate field.

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?


You use the years= argument:

def someform(forms.Form):
    birthdate = forms.DateField(widget=SelectDateWidget(years=range(1990,2011))
0

精彩评论

暂无评论...
验证码 换一张
取 消