Login

Month list for a select drop down

Author:
shwag
Posted:
April 18, 2007
Language:
Python
Version:
.96
Tags:
months select
Score:
-1 (after 1 ratings)

month_ids is a list of months like this... [('Apr07', 'April 2007'), ('Mar07', 'March 2007'), ('Feb07', 'February 2007')]

which can be used in a select box like this..

month = forms.ChoiceField(choices=(months))

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from mx.DateTime import *
from datetime import datetime

date = now()
month_ids = []
while not (date.month == 4 and date.year == 2004):
  month_ids.append((date.strftime('%b%y'),date.strftime('%B %Y')))
  date = date + RelativeDateTime(months=-1)

print month_ids
#date.days_in_month

More like this

  1. SelectDateWidget with format: day, month, year by zenx 5 years, 3 months ago
  2. Using reverse() to do redirects by ubernostrum 7 years, 7 months ago
  3. Calendar table by fauxparse 6 years, 11 months ago
  4. Timedelta template tag by dballanc 7 years, 11 months ago
  5. Timezone choice field for select box by jmunro 3 years ago

Comments

Please login first before commenting.