I am trying to set the edit type of a vector layer to use a value relation, by pyqgis. So my question is exactly the same as this, except now it is qgis 2.14. I found that setEditForm is deprecated and this method is recommended instead:
vlayer.editFormConfig().setWidgetType(index,"ValueRelation")
setWidgetType sets the edit widget correctly but then I have the same problems as in the question regarding qgis 2.0. I.e. python commands are processed without errors or warnings but the when I check the properties in QGIS, the widget settings are empty:
vlayer.valueRelation(index).mLayer = target_layer.id()
vlayer.valueRelation(index).mKey = key_field
vlayer.valueRelation(index).mValue = value_field
vlayer.valueRelation(index).mAllowNull = True
vlayer.valueRelation(index).mOrderByValue = True
How do I define the value relation by pyqgis in qgis 2.14?