LoginSignup
2
0

More than 5 years have passed since last update.

DjangoでDatetimeFieldのformに、HTML5の<input type="date/time">を使えるようにする

Posted at
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"
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0