Update variable in code
Aliefe2002 opened this issue · 1 comments
Aliefe2002 commented
Hi, i am trying to update a variable in code. However it is not being saved to db. So far my code looks like this;
variable = Variable.objects.get(id=34)
variable._update_value(new_value,time())
I have also tried this
variable = Variable.objects.get(id=34)
variable.update_values([new_value],[time()])
After these, when i say variable.prev_value, i get the new value, however it is not being saved. For example when i look at the variable state on admin panel it is not updated or when i pull the historical data of variable it is not there. update_values() method return true so i dont think there is a problem there.
(My device is generic device)
clavay commented
Hello,
please try :
variable = Variable.objects.get(id=34)
variable.update_values([new_value],[time()])
Variable.objects.write_multiple(items=[variable])