Skip to content

Instantly share code, notes, and snippets.

@fgaudin
Created April 29, 2011 20:34
Show Gist options
  • Save fgaudin/948989 to your computer and use it in GitHub Desktop.
Save fgaudin/948989 to your computer and use it in GitHub Desktop.
view
o = request.GET.get('o', 'last_comment_date')
if o not in ('subject', 'author', 'update_date', 'last_comment_date', 'category', 'comments', 'votes'):
o = 'last_comment_date'
if o == 'author':
order = 'owner__last_name'
else:
order = o
ot = request.GET.get('ot')
if ot not in ('asc', 'desc'):
if request.GET.get('o'):
ot = 'asc'
else:
ot = 'desc'
if ot == 'desc':
direction = '-'
else:
direction = ''
issues = Issue.objects.filter(state=ISSUE_STATE_OPEN,
category__in=[ISSUE_CATEGORY_BUG,
ISSUE_CATEGORY_FEATURE])\
.annotate(votes=Count('vote',
distinct=True),
comments=Count('comment',
distinct=True))\
.order_by(direction + order)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment