Don't crash if there's no ratings

This commit is contained in:
Joachim 2021-12-22 11:18:26 +01:00
parent 67092fd3e3
commit 0da0a62660

View file

@ -105,7 +105,9 @@ class AnnualSummary(View):
"book_pages_highest": book_list_by_pages.last(), "book_pages_highest": book_list_by_pages.last(),
"no_page_number": no_page_list, "no_page_number": no_page_list,
"ratings_total": len(ratings), "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(), "book_rating_highest": ratings.order_by("-rating").first(),
"best_ratings_books_ids": [ "best_ratings_books_ids": [
review.book.id for review in ratings.filter(rating=5) review.book.id for review in ratings.filter(rating=5)