views.py
def KEBReading1(request):
q2=KEBReading.objects.all().order_by('datetime_reading')[:30]
form = KEBReading_form()
monthform=MonthForm()
if request.method == "POST":
if request.POST.get('KEBsubmit'):
form = KEBReading_form(request.POST)
if form.is_valid():
try:
prevdate=KEBReading.objects.latest("datetime_reading")
print "teena"
date=form.cleaned_data["Date"]
print date
time=form.cleaned_data["Time"]
print time
kr_truepower_reading = form.cleaned_data["truepower_reading"]
kr_apparentpower_reading = form.cleaned_data["apparentpower_reading"]
truepower_consumed1=kr_truepower_reading-prevdate.truepower_reading
powerfactor1=((kr_truepower_reading-prevdate.truepower_reading)/(kr_apparentpower_reading-prevdate.apparentpower_reading))
form1=form.save(commit=False)
form1.datetime_reading__date=date
form1.datetime_reading___time=time
print type(date)
form1.truepower_consumed=truepower_consumed1
form1.powerfactor=powerfactor1
print form1.powerfactor
form1.save()
如何将检索到的日期字段和时间字段值合并到日期时间字段中以将其存储到数据库中。我有一个名为 datetime_reading 的文件。在我的页面中,我分别输入日期和时间字段。如何将日期和时间字段合并到单个日期时间字段中以将其存储在 DB 的 datetime_reading 列中