I tried out several permutations with mixed luck, but then happened upon the following recipe:
def month_year():
today = date.today()
today = date(today.year, today.month, 1)
dates = []
for i in range(1,13):
if (today.month > i):
month = today.month - i
year = today.year
else:
month = 12-(i-today.month)
year = today.year - 1
mon = date(year, month, 1)
dates.append((mon, mon.strftime("%B %Y")))
dates.reverse()
return dates
This creates a set of tuples, e.g.: (date(2009,3,1), 'March 2009'),
month = DateField(widget=Select(choices=month_year()))
This will produce the drop-down as above, and
form.cleaned_data['month']
Will actually return a datetime.date object (trust me, that's a good thing).
1 comment:
Microsoft Outlook 2010 to help control email volume, you can find the desired content, and perform operations at the appropriate time and location. Outlook 2010 download needs no introduction since it is the industry standard.
Post a Comment