@register.as_tag
def blog_months(*args):
 dates = BlogPost.objects.published().values_list(u'publish_date', flat=True)
 date_dicts = [{u'date': datetime(d.year, d.month, 1)} for d in dates]
 month_dicts = []
 for date_dict in date_dicts:
  if (date_dict not in month_dicts):
   month_dicts.append(date_dict)
 for (i, date_dict) in enumerate(month_dicts):
  month_dicts[i][u'post_count'] = date_dicts.count(date_dict)
 return month_dicts

@ register . as_tag def blog_months ( * args ) : dates = BlogPost . objects . published ( ) . values_list ( u'publish_date' , flat = True ) date_dicts = [ { u'date' : datetime ( d . year , d . month , 1 ) } for d in dates ] month_dicts = [ ] for date_dict in date_dicts : if ( date_dict not in month_dicts ) : month_dicts . append ( date_dict ) for ( i , date_dict ) in enumerate ( month_dicts ) : month_dicts [ i ] [ u'post_count' ] = date_dicts . count ( date_dict ) return month_dicts
put a list of dates for blog posts into the template context .