From 8ca2b55e7ef17c8ca9bf152e701cebebba53961a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 25 Feb 2022 12:04:21 -0800 Subject: [PATCH] Sort author books by rating --- bookwyrm/views/author.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py index b4eb7ef5..a2f5d03b 100644 --- a/bookwyrm/views/author.py +++ b/bookwyrm/views/author.py @@ -1,7 +1,7 @@ """ the good people stuff! the authors! """ from django.contrib.auth.decorators import login_required, permission_required from django.core.paginator import Paginator -from django.db.models import Q +from django.db.models import Avg, Q from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.decorators import method_decorator @@ -28,7 +28,8 @@ class Author(View): books = ( models.Work.objects.filter(Q(authors=author) | Q(editions__authors=author)) - .order_by("-published_date") + .annotate(Avg("editions__review__rating")) + .order_by("editions__review__rating__avg") .distinct() )