Fix date range on game overview

This commit is contained in:
Lukáš Kucharczyk 2023-10-01 21:51:32 +02:00
parent 760f12e6b1
commit 3e04ef2b83
2 changed files with 10 additions and 5 deletions

View File

@ -7,7 +7,7 @@
{% block content %}
<div class="dark:text-white max-w-sm sm:max-w-xl lg:max-w-3xl mx-auto">
<h1 class="text-4xl">{{ game.name }} (#{{ game.pk }})</h1>
<h2 class="text-lg my-2 ml-2">{{ total_playtime }} ({{ first_session.timestamp_end | date:"M Y"}} — {{ first_session.timestamp_end | date:"M Y"}}) </h2>
<h2 class="text-lg my-2 ml-2">{{ total_playtime }} ({{ first_session.timestamp_end | date:"M Y"}} — {{ last_session.timestamp_end | date:"M Y"}}) </h2>
<hr class="border-slate-500">
<h1 class="text-3xl mt-4 mb-1">Editions</h1>
<ul>
@ -33,7 +33,7 @@
<h1 class="text-3xl mt-4 mb-1">Sessions</h1>
<ul>
{% for session in sessions %}
<li class="sm:pl-2">{{ session.timestamp_end | date:"d/m/Y" }} ({{ session.device.get_type_display | default:"Unknown" }}, {{ session.duration_formatted }})</li>
<li class="sm:pl-2">{{ session.timestamp_start | date:"d/m/Y" }} ({{ session.device.get_type_display | default:"Unknown" }}, {{ session.duration_formatted }})</li>
{% endfor %}
</ul>

View File

@ -98,10 +98,15 @@ def view_game(request, game_id=None):
context["game"] = game
context["editions"] = Edition.objects.filter(game_id=game_id)
context["purchases"] = Purchase.objects.filter(edition__game_id=game_id)
context["sessions"] = Session.objects.filter(purchase__edition__game_id=game_id)
context["sessions"] = Session.objects.filter(
purchase__edition__game_id=game_id
).order_by("-timestamp_start")
context["total_playtime"] = context["sessions"].total_duration()
context["last_session"] = context["sessions"].last
context["first_session"] = context["sessions"].first
# here first and last is flipped
# because sessions are ordered from newest to oldest
# so the most recent are on top
context["last_session"] = context["sessions"].first()
context["first_session"] = context["sessions"].last()
return render(request, "view_game.html", context)