forms.py
class ReportForm(forms.ModelForm):
class Meta:
model = Report
manual_date = forms.DateField(widget=forms.DateInput())
widgets = {'manual_date': forms.DateInput(attrs{'size':'15','id':'datepicker1',}),'manual_time':
forms.TimeInput(attrs={'size':'8','class':'time_field', },format='%H:%M')
}
仅接受选定(mm/dd/yyyy and 24hrs)
格式的表单接受输入。如果所选格式位于(dd/mm/yyyy and 12hrs)
,我将无法保存更改。
谢谢
答案 0 :(得分:3)
最后这对我有用
class ReportForm(forms.ModelForm):
manual_date = forms.DateField(input_formats=['%m/%d/%Y','%d/%m/%Y'],
widget=forms.DateInput(attrs={'size':'15','id':'datepicker'},format=["%m/%d/%Y","%d/%m/%Y"]))
manual_time = forms.TimeField(input_formats=['%H:%M','%I:%M %p'],
widget=forms.TimeInput(attrs={'size':'8','class':'time_field'},format=["%H:%M","%I:%M %p"]))
问题在于Input_formats,因此在给定解决方案的情况下,在日期和时间input_formats中进行更改。
希望这有助于某人!谢谢