views.py
event_full_datetime =datetime(Editrow.datetime_reading.year,Editrow.datetime_reading.month,Editrow.datetime_reading.day, Editrow.datetime_reading.hour,
Editrow.datetime_reading.minute, Editrow.datetime_reading.second)
date=event_full_datetime.year ,event_full_datetime.month,event_full_datetime.day
time=event_full_datetime.hour,event_full_datetime.minute
print time
print date
form = KEBReading_form()
form.Date=date
form.Time=time
form = KEBReading_form(instance=Editrow)
在數據庫中我有一個日期時間字段,但在我的表單中我有單獨的日期和時間字段。我想用值填充日期和時間字段,當我點擊編輯。該實例應該具有的所有值如何獲得單獨的日期和時間表單數據庫日期時間字段
我把它作爲
form = KEBReading_form(instance=Editrow)
print "htjrit"
print instance.datetime_reading.date()
form = KEBReading_form(initial={'Date': instance.datetime_reading.date(),
'Time': instance.datetime_reading.time()
}
)
return render_to_response('keb.html',{'KEBReading_form':form,'MonthForm':monthform,'q2':q2,},context_instance=RequestContext(request))
感謝洛特:)它的工作 – prithu 2013-02-19 12:49:43
@prithu,好,但要確保你結合當你想保存模型實例時,它再次正確。 – Rohan 2013-02-19 12:52:38