我在使用日期时间和日期选择器时遇到了一些问题。我有一个带有 2 个日期选择器字段(To 和 From)的模型表单,可以选择并保存日期。问题是,当我去编辑表单时,日期似乎显示为输入日期的前一天/后一天,或者只是显示当前日期。
我的模型.py:
from_when = DateTimeField(_('From'), blank=True, null=True)
to_when = DateTimeField(_('To'), blank=True, null=True)
表格.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
任何想法为什么会出现这个问题?