diff options
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/extras/widgets.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/django/forms/extras/widgets.py b/django/forms/extras/widgets.py index 0b96dc4153..5590a9806a 100644 --- a/django/forms/extras/widgets.py +++ b/django/forms/extras/widgets.py @@ -51,16 +51,23 @@ class SelectDateWidget(Widget): day_field = '%s_day' year_field = '%s_year' - def __init__(self, attrs=None, years=None, required=True): - # years is an optional list/tuple of years to use in the "year" select box. + def __init__(self, attrs=None, years=None, required=True, months=None): self.attrs = attrs or {} self.required = required + + # Optional list or tuple of years to use in the "year" select box. if years: self.years = years else: this_year = datetime.date.today().year self.years = range(this_year, this_year+10) + # Optional dict of months to use in the "month" select box. + if months: + self.months = months + else: + self.months = MONTHS + def render(self, name, value, attrs=None): try: year_val, month_val, day_val = value.year, value.month, value.day @@ -80,7 +87,7 @@ class SelectDateWidget(Widget): year_val, month_val, day_val = [int(v) for v in match.groups()] choices = [(i, i) for i in self.years] year_html = self.create_select(name, self.year_field, value, year_val, choices) - choices = list(six.iteritems(MONTHS)) + choices = list(six.iteritems(self.months)) month_html = self.create_select(name, self.month_field, value, month_val, choices) choices = [(i, i) for i in range(1, 32)] day_html = self.create_select(name, self.day_field, value, day_val, choices) |
