From 50e7efcfae62d0433d4166da9f174fec0339bc2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sun, 9 Feb 2025 09:00:28 +0100 Subject: [PATCH] Fix today's playtime stats --- games/views/general.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/games/views/general.py b/games/views/general.py index 3c819e9..c607680 100644 --- a/games/views/general.py +++ b/games/views/general.py @@ -16,11 +16,15 @@ from games.models import Game, Platform, Purchase, Session def model_counts(request: HttpRequest) -> dict[str, bool]: + now = timezone_now() + this_day, this_month, this_year = now.day, now.month, now.year today_played = Session.objects.filter( - timestamp_start__year=2025, timestamp_start__day=8, timestamp_start__month=2 + timestamp_start__day=this_day, + timestamp_start__month=this_month, + timestamp_start__year=this_year, ).aggregate(time=Sum(F("duration_calculated")))["time"] last_7_played = Session.objects.filter( - timestamp_start__gte=(timezone_now() - timedelta(days=7)) + timestamp_start__gte=(now - timedelta(days=7)) ).aggregate(time=Sum(F("duration_calculated")))["time"] return {