日期时间返回不同的日期输入

时间:2013-09-10 10:27:19

标签: django date datetime picker

我在使用datetime和datepicker时遇到了一些问题。我有一个带有2个日期选择器字段(To和From)的模型表单,可以选择并保存日期。问题是,当我去编辑表单时,日期似乎显示为输入日期的前一天或后一天或只显示当前日期。

我的model.py:

    from_when = DateTimeField(_('From'), blank=True, null=True)
    to_when = DateTimeField(_('To'), blank=True, null=True)

forms.py:

    class ScheduleForm(ModelForm):
      class Meta:
        model = Schedule
        fields = ['from_when', 'to_when',]       

    def __init__(self, *args, **kwargs):
        super(ScheduleForm, self).__init__(*args, **kwargs)
        self.name = 'scheduleform'
        self.title = _('Add/Edit Schedule')        
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.form_layout()

    def form_layout(self):
        self.helper.layout = Layout(
        Div(
            Div(                    
                Div(
                    # use the jQuery datepicker plugin, if available
                    Field('from_when', css_class='datepicker'),
                    # use the jQuery datepicker plugin, if available
                    Field('to_when', css_class='datepicker'),                        
                    css_class='span4',
                ),                    
                css_class='row-fluid',
            ),
        ),
    )

     def save(self, force_insert=False,
            force_update=False, *args, **kwargs):        
        course = super(ScheduleForm, self).save(
                commit=True, *args, **kwargs)

    return course

可能出现此问题的任何想法?

0 个答案:

没有答案