I want to update my date field to the current date when a checkbox has been checked.The date field is Sur_com, the checkbox is Sur_check.
I have tried codes below:
First:
layer = qgis.utils.iface.activeLayer()
f1 = 'Sur_com'
f2 = 'Sur_check'
def updateDATE(f1,f2):
e = QgsExpression("$now")
for feat in layer():
if f2 is True:
feat[f1] = e.evaluate()
layer.updateFeature(feat)
Second:
layer = qgis.utils.iface.activeLayer()
f1 = 'Sur_com'
f2 = 'Sur_check'
e = QgsExpression("$now")
if f2 is True:
f1 = e.evaluate()
layer.updateFeature()
Although those codes don't give any error and are executed in the python console, the date field still needs to click to appear today's date.
Is it my code that has a problem?