Name
Start
End
Duration
{% for data in dataset %}
-
{{ data.purchase }}
+
{{ data.timestamp_start }}
{{ data.timestamp_end }}
{{ data.time_delta }}
diff --git a/src/web/tracker/urls.py b/src/web/tracker/urls.py
index 28c8796..fb8944f 100644
--- a/src/web/tracker/urls.py
+++ b/src/web/tracker/urls.py
@@ -7,4 +7,9 @@ urlpatterns = [
path("add-session/", views.add_session, name="add_session"),
path("add-purchase/", views.add_purchase, name="add_purchase"),
path("list-sessions/", views.list_sessions, name="list_sessions"),
+ path(
+ "list-sessions/by-purchase/
",
+ views.list_sessions,
+ name="list_sessions",
+ ),
]
diff --git a/src/web/tracker/views.py b/src/web/tracker/views.py
index 1f025ed..54f95f3 100644
--- a/src/web/tracker/views.py
+++ b/src/web/tracker/views.py
@@ -4,6 +4,7 @@ from .models import Game, Platform, Purchase, Session
from .forms import SessionForm, PurchaseForm, GameForm
from datetime import datetime
from django.db.models import ExpressionWrapper, F, DurationField
+import logging
def add_session(request):
@@ -18,9 +19,16 @@ def add_session(request):
return render(request, "add_session.html", context)
-def list_sessions(request):
+def list_sessions(request, purchase_id=None):
context = {}
- dataset = Session.objects.annotate(
+
+ if purchase_id != None:
+ dataset = Session.objects.filter(purchase=purchase_id)
+ context["purchase"] = Purchase.objects.get(id=purchase_id)
+ else:
+ dataset = Session.objects.all()
+
+ dataset = dataset.annotate(
time_delta=ExpressionWrapper(
F("timestamp_end") - F("timestamp_start"), output_field=DurationField()
)