[PYTHON] Allow HTML5 <input type = "date / time"> to be used in DatetimeField form in Django

widgets.py


# coding: utf-8
from __future__ import unicode_literals
from __future__ import absolute_import
from django import forms


class DateTimeWidget(forms.SplitDateTimeWidget):
    """
    A Widget that splits datetime input into two <input type="date"> and <input type="time"> inputs.
    """
    def __init__(self, attrs=None, date_format=None, time_format=None):
        super(DateTimeWidget, self).__init__(attrs, date_format, time_format)
        self.widgets[0].input_type = "date"
        self.widgets[1].input_type = "time"

Recommended Posts

Allow HTML5 <input type = "date / time"> to be used in DatetimeField form in Django
Set the form DateField to type = date in Django
Use <input type = "date"> in Flask
How to convert DateTimeField format in Django
Dynamically add fields to Form objects in Django
To represent date, time, time, and seconds in Python
Convert timezoned date and time to Unixtime in Python2.7
[Go language] How to get terminal input in real time
[Django] How to give input values in advance with ModelForm
Display the time in Django according to the user's region (UTC)
Allow Python to select strings in input files from folders
Precautions when changing unix time to datetime type in pandas
Check the Check button in Tkinter to allow Entry to be edited