From 0da0a626609794c9bed84dac823e151de6cc4728 Mon Sep 17 00:00:00 2001 From: Joachim Date: Wed, 22 Dec 2021 11:18:26 +0100 Subject: [PATCH] Don't crash if there's no ratings --- bookwyrm/views/annual_summary.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bookwyrm/views/annual_summary.py b/bookwyrm/views/annual_summary.py index 26374ea9..cfdd6093 100644 --- a/bookwyrm/views/annual_summary.py +++ b/bookwyrm/views/annual_summary.py @@ -105,7 +105,9 @@ class AnnualSummary(View): "book_pages_highest": book_list_by_pages.last(), "no_page_number": no_page_list, "ratings_total": len(ratings), - "rating_average": round(ratings_stats["rating__avg"], 2), + "rating_average": round( + ratings_stats["rating__avg"] if ratings_stats["rating__avg"] else 0, 2 + ), "book_rating_highest": ratings.order_by("-rating").first(), "best_ratings_books_ids": [ review.book.id for review in ratings.filter(rating=5)