自定义SplitDateTimeWidget

时间:2016-08-03 15:29:54

标签: django

我正在编辑SplitDateTimeWidget以包含SelectTimeWidget和SelectDateWidget。但是我收到了错误

ImportError: cannot import name SelectTimeWidget

正在导入SelectDateWidget以及它正常工作

class SplitDateTimeWidget(forms.MultiWidget):
    """
    A Widget that splits datetime input into two <input type="text"> boxes.
    """
    supports_microseconds = False

    def __init__(self, attrs=None, date_format=None, time_format=None):
        widgets = (SelectDateWidget(attrs=attrs),
                   TimeInput(attrs=attrs, format=time_format))
        super(SplitDateTimeWidget, self).__init__(widgets, attrs)

    def decompress(self, value):
        if value:
            value = to_current_timezone(value)
            return [value.date(), value.time().replace(microsecond=0)]
        return [None, None]

我尝试导入并添加SelectTimeWidget就像这样...

   widgets = (SelectDateWidget(attrs=attrs),
               SelectTimeWidget(attrs=attrs))

我收到错误消息?怎么会?

编辑 - 导入

from django.forms.extras.widgets import SelectTimeWidget, SelectDateWidget
from django.forms.widgets import Widget, Select, MultiWidget

所以,当我自己导入SelectDateWidget并且只在它可以工作的多功能小部件中使用它时,所以我不得不大声地有两个小部件用于什么原因然后我试图单独导入SelectTimeWidget并使用它和我仍然得到同样的错误

0 个答案:

没有答案