Skip to content

Instantly share code, notes, and snippets.

@gladson
Created November 28, 2011 06:15
Show Gist options
  • Select an option

  • Save gladson/1399330 to your computer and use it in GitHub Desktop.

Select an option

Save gladson/1399330 to your computer and use it in GitHub Desktop.
fdsgdfgdf
import time
from calendar import month_name
def mkmonth_lst():
if not Post.objects.count(): return []
year, month = time.localtime()[:2]
first = Post.objects.order_by("created")[0]
fyear = first.created.year
fmonth = first.created.month
months = []
for y in range(year, fyear-1, -1):
start, end = 12, 0
if y == year: start = month
if y == fyear: end = fmonth-1
for m in range(start, end, -1):
months.append((y, m, month_name[m]))
return months
def month(request, year, month):
posts = Post.objects.filter(created__year=year, created__month=month)
return render_to_response("blog/list.html", dict(post_list=posts, user=request.user,
months=mkmonth_lst(), archive=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment