From 67b06d7856ddaa95fc1704e17d69acf1a2f40af3 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sat, 13 Apr 2024 00:51:14 -0500 Subject: [PATCH] Fix datetime widget --- judge/widgets/datetime.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/judge/widgets/datetime.py b/judge/widgets/datetime.py index 7b95d4e..3e068f4 100644 --- a/judge/widgets/datetime.py +++ b/judge/widgets/datetime.py @@ -2,6 +2,7 @@ from django import forms from django.templatetags.static import static from django.utils.html import format_html from django.forms.utils import flatatt +from django.utils.dateparse import parse_datetime class DateTimePickerWidget(forms.DateTimeInput): @@ -10,6 +11,13 @@ class DateTimePickerWidget(forms.DateTimeInput): def render(self, name, value, attrs=None, renderer=None): if value is None: value = "" + elif isinstance(value, str): + # Attempt to parse the string back to datetime + parsed_date = parse_datetime(value) + if parsed_date is not None: + value = parsed_date.strftime("%Y-%m-%dT%H:%M") + else: + value = "" else: value = value.strftime("%Y-%m-%dT%H:%M")