Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.6.2
-
None
-
PySide 1.1.2 for Python 2.6 on Windows XP
-
87f9a44ef04ac12d0180bb556cab7f3528ba036a
Description
I use a PostgreSql database, whose table and field names contain uppercase and lowercase letters.
To refer to these fields it is necessary to place them between quotation marks (example : QSqlRelation("\"TableName\"", "\"FieldName1\"", "\"FieldName2\""))
The standard QSqlRelationDelegate does not work correctly in that case (the fields are not updated in the database).
To make it work I had to subclass QSqlRelationDelegate and add .replace("\"", "") in the setModelData() function :
def setModelData(self, editor, model, index): if editor.metaObject().className() == "QComboBox": if model.relationModel(index.column()) is not None: currentItem = editor.currentIndex() childModel = model.relationModel(index.column()) childColIndex = childModel.fieldIndex(model.relation(index.column()).displayColumn().replace("\"", "")) childEditIndex = childModel.fieldIndex(model.relation(index.column()).indexColumn().replace("\"", "")) model.setData(index, childModel.data(childModel.index(currentItem, childColIndex), Qt.DisplayRole), Qt.DisplayRole) model.setData(index, childModel.data(childModel.index(currentItem, childEditIndex), Qt.EditRole), Qt.EditRole) return QItemDelegate.setModelData(self, editor, model, index)