From cdfe5d99d6179557f399d41c377c742340b120da Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 14 Dec 2014 10:28:58 -0500 Subject: [PATCH] add is_free annotations on subject lists --- frontend/templates/subjects.html | 16 +++++++++++----- frontend/views.py | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/frontend/templates/subjects.html b/frontend/templates/subjects.html index 01cc4427..377c59c3 100644 --- a/frontend/templates/subjects.html +++ b/frontend/templates/subjects.html @@ -8,17 +8,23 @@

Below is a list of subjects for books that users have added to wishlists. It is here primarily to show what subjects are present - in the database to guide further development. You can order by the - subject name or by the - number of works - with that subject. + in the database to guide further development.

+

diff --git a/frontend/views.py b/frontend/views.py index ba94d723..c31f5bb2 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -768,12 +768,19 @@ def googlebooks(request, googlebooks_id): def subjects(request): order = request.GET.get('order') subjects = models.Subject.objects.all() - subjects = subjects.annotate(Count('works')) - - if request.GET.get('order') == 'count': - subjects = subjects.order_by('-works__count') + subjects = subjects + if request.GET.get('subset') == 'free': + subjects = models.Subject.objects.filter(works__is_free = True).annotate(Count('works__is_free')) + if request.GET.get('order') == 'count': + subjects = subjects.order_by('-works__is_free__count') + else: + subjects = subjects.order_by('name') else: - subjects = subjects.order_by('name') + subjects = models.Subject.objects.all().annotate(Count('works')) + if request.GET.get('order') == 'count': + subjects = subjects.order_by('-works__count') + else: + subjects = subjects.order_by('name') return render(request, 'subjects.html', {'subjects': subjects})