视图.py
AppTruepower = form.cleaned_data['truepower_reading']
AppApparent = form.cleaned_data['apparentpower_reading']
AppVoltage = form.cleaned_data['voltage_reading']
AppDate = form.cleaned_data['Date']
AppTime = form.cleaned_data['Time']
prevdate=KEBReading.objects.latest("id")
print prevdate.truepower_reading
print id
KEBReading.objects.filter(id=id).update(truepower_reading=AppTruepower,apparentpower_reading=AppApparent,
voltage_reading=AppVoltage,datetime_reading=datetime.combine(AppDate,AppTime))
a=KEBReading.objects.filter(id=id).values("truepower_reading")
print a
b=KEBReading.objects.filter(id=id).values("apparentpower_reading")
print b
print prevdate.truepower_reading
在 django 表单中编辑一行时。我需要访问前一行来做一些计算。sumbody 可以建议我如何获得上一行。如果我使用 model.s.object.latest() 我会输入最后一行,但在我的情况下,我需要获取上一行,即我要编辑的当前行的前一行。