2022-09-15 07:05:02 +00:00
|
|
|
from django import forms
|
2024-04-13 03:26:17 +00:00
|
|
|
from django.templatetags.static import static
|
|
|
|
from django.utils.html import format_html
|
|
|
|
from django.forms.utils import flatatt
|
2022-09-15 07:05:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DateTimePickerWidget(forms.DateTimeInput):
|
2024-04-13 03:26:17 +00:00
|
|
|
input_type = "datetime-local"
|
2022-09-15 07:05:02 +00:00
|
|
|
|
2024-04-13 03:26:17 +00:00
|
|
|
def render(self, name, value, attrs=None, renderer=None):
|
|
|
|
if value is None:
|
|
|
|
value = ""
|
|
|
|
else:
|
|
|
|
value = value.strftime("%Y-%m-%dT%H:%M")
|
2022-09-15 07:05:02 +00:00
|
|
|
|
2024-04-13 03:26:17 +00:00
|
|
|
final_attrs = self.build_attrs(
|
|
|
|
attrs, {"type": self.input_type, "name": name, "value": value}
|
2022-09-15 07:05:02 +00:00
|
|
|
)
|
2024-04-13 03:26:17 +00:00
|
|
|
return format_html("<input{}>", flatatt(final_attrs))
|