Enable admin site

This commit is contained in:
Lukáš Kucharczyk 2023-01-02 19:36:22 +01:00
parent 3cdfb94fe2
commit fe7aec1b87
3 changed files with 17 additions and 2 deletions

View File

@ -1,3 +1,8 @@
from django.contrib import admin from django.contrib import admin
from .models import Game, Purchase, Platform, Session
# Register your models here. # Register your models here.
admin.site.register(Game)
admin.site.register(Purchase)
admin.site.register(Platform)
admin.site.register(Session)

View File

@ -1,4 +1,5 @@
from django.db import models from django.db import models
from datetime import timedelta
class Game(models.Model): class Game(models.Model):
@ -31,12 +32,20 @@ class Session(models.Model):
purchase = models.ForeignKey("Purchase", on_delete=models.CASCADE) purchase = models.ForeignKey("Purchase", on_delete=models.CASCADE)
timestamp_start = models.DateTimeField() timestamp_start = models.DateTimeField()
timestamp_end = 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) duration_calculated = models.DurationField(blank=True, null=True)
note = models.TextField(blank=True, null=True) note = models.TextField(blank=True, null=True)
def __str__(self): 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): def calculated_duration(self):
return self.timestamp_end - self.timestamp_start 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()
)

View File

@ -19,6 +19,7 @@ from django.views.generic import RedirectView
urlpatterns = [ urlpatterns = [
path("admin/", admin.site.urls),
path("", RedirectView.as_view(url="/tracker/list-sessions")), path("", RedirectView.as_view(url="/tracker/list-sessions")),
path("tracker/", include("tracker.urls")), path("tracker/", include("tracker.urls")),
] ]