Python formatting

This commit is contained in:
Mouse Reeve 2022-01-06 09:48:36 -08:00
parent 461bfd0ce7
commit b8c72d75e5

View file

@ -29,24 +29,50 @@ def about(request):
books = models.Edition.objects.exclude(cover__exact="")
total_ratings = models.Review.objects.filter(user__local=True, deleted=False).count()
data["top_rated"] = books.annotate(
rating=Avg("review__rating", filter=Q(review__user__local=True, review__deleted=False)),
rating_count=Count("review__rating", filter=Q(review__user__local=True, review__deleted=False)),
).annotate(
weighted=F("rating") * F("rating_count") / total_ratings
).filter(weighted__gt=0).order_by("-weighted").first()
total_ratings = models.Review.objects.filter(
user__local=True, deleted=False
).count()
data["top_rated"] = (
books.annotate(
rating=Avg(
"review__rating",
filter=Q(review__user__local=True, review__deleted=False),
),
rating_count=Count(
"review__rating",
filter=Q(review__user__local=True, review__deleted=False),
),
)
.annotate(weighted=F("rating") * F("rating_count") / total_ratings)
.filter(weighted__gt=0)
.order_by("-weighted")
.first()
)
data["controversial"] = books.annotate(
deviation=StdDev("review__rating", filter=Q(review__user__local=True, review__deleted=False)),
rating_count=Count("review__rating", filter=Q(review__user__local=True, review__deleted=False)),
).annotate(
weighted=F("deviation") * F("rating_count") / total_ratings
).filter(weighted__gt=0).order_by("-weighted").first()
data["controversial"] = (
books.annotate(
deviation=StdDev(
"review__rating",
filter=Q(review__user__local=True, review__deleted=False),
),
rating_count=Count(
"review__rating",
filter=Q(review__user__local=True, review__deleted=False),
),
)
.annotate(weighted=F("deviation") * F("rating_count") / total_ratings)
.filter(weighted__gt=0)
.order_by("-weighted")
.first()
)
data["wanted"] = books.annotate(
data["wanted"] = (
books.annotate(
shelf_count=Count("shelves", filter=Q(shelves__identifier="to-read"))
).order_by("-shelf_count").first()
)
.order_by("-shelf_count")
.first()
)
return TemplateResponse(request, "about/about.html", data)