Login

Month list for a select drop down

Author:
shwag
Posted:
April 18, 2007
Language:
Python
Version:
.96
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. Template tag - list punctuation for a list of items by shapiromatron 3 months ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 3 months, 1 week ago
  3. Serializer factory with Django Rest Framework by julio 10 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 10 months, 3 weeks ago
  5. Help text hyperlinks by sa2812 11 months, 3 weeks ago

Comments

Please login first before commenting.