Answer the question
In order to leave comments, you need to log in
How to select phone numbers by subscriber id in the table?
There are 2 tables: CALLS and SUBSCRIBERS. The second contains the subscriber_id, his full name and phone number, and the first contains the call_id, subscriber_id (that is, you need to select), the subscriber's phone number (you need to select, but you need to filter it somehow so that the choice is possible only if the subscriber_id is in the table CALLS matched the subscriber_id in the SUBSCRIBERS table). This is how adding a table works for me now:
def addTable(i):
if i == 1:
TableName = "Callers";
ColNames = ["ФИО", "Номер телефона"];
ColWidth = [300, 300];
elif i == 2:
TableName = "Calls";
ColNames = ["Абонент", "Номер абонента"];
ColWidth = [300, 300];
global stm;
stm = QtSql.QSqlRelationalTableModel(parent = window);
tv.setModel(stm);
stm.setTable(TableName);
stm.setSort(1, QtCore.Qt.AscendingOrder);
if i == 2
stm.setRelation(1, QtSql.QSqlRelation("Callers", "CallersID", "FullName"));
stm.setRelation(2, QtSql.QSqlRelation("Callers", "CallersID", "CallerPhone"));#Где CallersID поле id_абонента, FullName - ФИО абонента, а CallerPhone - телефон абонента.
stm.select();
k = 0;
for ColName in ColNames:
k = k + 1;
stm.setHeaderData(k, QtCore.Qt.Horizontal, ColName);
if TableName == "Calls":
tv.setItemDelegateForColumn(1, QtSql.QSqlRelationalDelegate(tv));
tv.setItemDelegateForColumn(2, QtSql.QSqlRelationalDelegate(tv));
tv.hideColumn(0);
k = 0;
for ColW in ColWidth:
k = k + 1;
tv.setColumnWidth(k, ColW);
if TableName != "Calls":
btnDel.setEnabled(False);
else:
btnDel.setEnabled(True);
btnAdd.setEnabled(True);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question