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()
how do i merge the date field and time field value i retrieved into a datetime field to store it the database. i have a filed called datetime_reading. and in my page i enter date and time field separately. how do i merge the date and time field into a single datetime field to store it in datetime_reading column in DB
To merge date and time you need to use datetime.combine
datetime.combine(date, time)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With