-def badge(request, id):
- badge = get_object_or_404(Badge, id=id)
- awards = Award.objects.extra(
- select={'id': 'auth_user.id',
- 'name': 'auth_user.username',
- 'rep':'forum_user.reputation',
- 'gold': 'forum_user.gold',
- 'silver': 'forum_user.silver',
- 'bronze': 'forum_user.bronze'},
- tables=['award', 'auth_user', 'forum_user'],
- where=['badge_id=%s AND user_id=auth_user.id AND forum_user.user_ptr_id = auth_user.id'],
- params=[id]
- ).distinct('id')
+def badge(request, id, slug):
+ badge = Badge.objects.get(id=id)
+ awards = Award.objects.filter(badge=badge).annotate(count=Count('user')).distinct('user').order_by('-count')