sort suggestions
@@ -3,6 +3,7 @@ from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse, reverse_lazy
+from django.db.models import Count
from django.http import Http404, HttpResponseRedirect
from django.utils import timezone
from django.utils.decorators import method_decorator
@@ -320,7 +321,9 @@ class PartnerSuggestionView(FormView):
context = super(PartnerSuggestionView, self).get_context_data(**kwargs)
- all_suggestions = Suggestion.objects.all()
+ all_suggestions = Suggestion.objects.all() \
+ .annotate(total_upvoted_users=Count('upvoted_users')) \
+ .order_by('-total_upvoted_users')
if all_suggestions.count() > 0:
context['all_suggestions'] = all_suggestions
