From 7dfd91421e644b9fd6ac57dd0f63ba44c6c4c59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Mon, 16 Jan 2023 23:23:00 +0100 Subject: [PATCH] Try fixing the problem --- src/web/tracker/forms.py | 33 ++++++++++++++++++++++++++------- src/web/tracker/views.py | 6 +++++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/web/tracker/forms.py b/src/web/tracker/forms.py index 2cda2b9..f28031a 100644 --- a/src/web/tracker/forms.py +++ b/src/web/tracker/forms.py @@ -4,6 +4,23 @@ from .models import Game, Platform, Purchase, Session class SessionForm(forms.ModelForm): + custom_datetime_widget = forms.SplitDateTimeWidget( + date_format=("%d-%m-%Y"), + time_format=("%H:%M"), + date_attrs={"type": "date"}, + time_attrs={"type": "time"}, + ) + timestamp_start = forms.SplitDateTimeField( + input_date_formats="['%d-%m-%Y]", + input_time_formats="['%H:%M']", + widget=custom_datetime_widget, + ) + timestamp_end = forms.SplitDateTimeField( + input_date_formats="['%d-%m-%Y]", + input_time_formats="['%H:%M']", + widget=custom_datetime_widget, + ) + class Meta: model = Session fields = [ @@ -13,13 +30,15 @@ class SessionForm(forms.ModelForm): "duration_manual", "note", ] - custom_datetime_widget = forms.SplitDateTimeWidget( - date_attrs={"type": "date"}, time_attrs={"type": "time"} - ) - widgets = { - "timestamp_start": custom_datetime_widget, - "timestamp_end": custom_datetime_widget, - } + + # fields_classes = { + # "timestamp_start": custom_datetime_field, + # "timestamp_end": custom_datetime_field, + # } + # widgets = { + # "timestamp_start": custom_datetime_widget, + # "timestamp_end": custom_datetime_widget, + # } class PurchaseForm(forms.ModelForm): diff --git a/src/web/tracker/views.py b/src/web/tracker/views.py index f12157c..943346f 100644 --- a/src/web/tracker/views.py +++ b/src/web/tracker/views.py @@ -23,7 +23,11 @@ def add_session(request): context = {} now = now_with_tz() last = Session.objects.all().last() - initial = {"timestamp_start": now, "purchase": last.purchase} + initial = { + "timestamp_start_0": now.date(), + "timestamp_start_1": now.time(), + "purchase": last.purchase, + } form = SessionForm(request.POST or None, initial=initial) if form.is_valid(): form.save() -- 2.40.1