From fe7aec1b87e37d3003f7868000b1d4168c6c220e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Mon, 2 Jan 2023 19:36:22 +0100 Subject: [PATCH] Enable admin site --- src/web/tracker/admin.py | 5 +++++ src/web/tracker/models.py | 13 +++++++++++-- src/web/web/urls.py | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/web/tracker/admin.py b/src/web/tracker/admin.py index 8c38f3f..0bdd83d 100644 --- a/src/web/tracker/admin.py +++ b/src/web/tracker/admin.py @@ -1,3 +1,8 @@ from django.contrib import admin +from .models import Game, Purchase, Platform, Session # Register your models here. +admin.site.register(Game) +admin.site.register(Purchase) +admin.site.register(Platform) +admin.site.register(Session) diff --git a/src/web/tracker/models.py b/src/web/tracker/models.py index b18867c..8ac5375 100644 --- a/src/web/tracker/models.py +++ b/src/web/tracker/models.py @@ -1,4 +1,5 @@ from django.db import models +from datetime import timedelta class Game(models.Model): @@ -31,12 +32,20 @@ class Session(models.Model): purchase = models.ForeignKey("Purchase", on_delete=models.CASCADE) timestamp_start = models.DateTimeField() timestamp_end = models.DateTimeField() - duration_manual = models.DurationField(blank=True, null=True) + duration_manual = models.DurationField(blank=True, null=True, default=timedelta(0)) duration_calculated = models.DurationField(blank=True, null=True) note = models.TextField(blank=True, null=True) def __str__(self): - return self.purchase + mark = ", manual" if self.duration_manual != None else "" + return f"{str(self.purchase)} {str(self.timestamp_start.date())} ({self.total_duration()}{mark})" def calculated_duration(self): return self.timestamp_end - self.timestamp_start + + def total_duration(self): + return ( + self.calculated_duration() + if self.duration_manual == None + else self.duration_manual + self.calculated_duration() + ) diff --git a/src/web/web/urls.py b/src/web/web/urls.py index b9a58e8..33d8170 100644 --- a/src/web/web/urls.py +++ b/src/web/web/urls.py @@ -19,6 +19,7 @@ from django.views.generic import RedirectView urlpatterns = [ + path("admin/", admin.site.urls), path("", RedirectView.as_view(url="/tracker/list-sessions")), path("tracker/", include("tracker.urls")), ]