Display total hours played on homepage
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-01-05 11:24:07 +01:00
parent fdb9aa8e84
commit 32f10e183e
3 changed files with 9 additions and 2 deletions

View File

@ -5,7 +5,8 @@ from .forms import SessionForm, PurchaseForm, GameForm, PlatformForm
from datetime import datetime
from zoneinfo import ZoneInfo
from django.conf import settings
from common.util.time import now as now_with_tz
from common.util.time import now as now_with_tz, format_duration
from django.db.models import Sum
def model_counts(request):
@ -102,4 +103,9 @@ def add_platform(request):
def index(request):
context = {}
result = Session.objects.all().aggregate(Sum("duration_calculated"))
context["total_duration"] = format_duration(
result["duration_calculated__sum"], "%H hours %m minutes"
)
context["title"] = "Index"
return render(request, "index.html", context)