PDA

View Full Version : PyQt - Mapping multiple forms to a database



peterjb31
23rd April 2008, 10:40
I have a database with several tables which I want to access through a form. I am trying to access different tables using different tabs in a mainwindow. The issue is that the second mapping listed within the class doesn't seem to respond.

I have the following fields defined at the top:
SUPID, SUPTITLEID, SUPCOMPNAME, SUPFORENAME, SUPSURNAME, SUPADDLINE1, SUPADDLINE2, SUPADDTOWN, SUPADDCOUNTY, SUPADDPOSTCODE, SUPPHONE, SUPEMAIL, CUSTITLEID, CUSNAME, CUSFORENAME, CUSSURNAME, CUSDELADDLINE1, CUSDELADDLINE2, CUSDELADDTOWN, CUSDELADDCOUNTY, CUSDELADDPOSTCODE, CUSBILLADDLINE1, CUSBILLADDLINE2, CUSBILLADDTOWN, CUSBILLADDCOUNTY, CUSBILLADDPOSTCODE, CUSPHONE, CUSEMAIL, ID, NAME, = range(32)

And then map to them using this syntax:
self.supplierMapper.addMapping(self.supplierSurnam eEdit, SUPSURNAME)

Is it because of the ordering for the fields at the top of the class. How do I make sure that one of the variables at the top of the class is mapped to the right field within the database.

Any help would be hugely appreciated.

jacek
1st May 2008, 22:03
What is that supplierMapper exactly?

peterjb31
1st May 2008, 22:37
supplierMapper is a QDataWidgetMapper which maps variable to fields in a table.

self.supplierMapper = QDataWidgetMapper(self)
self.supplierMapper.setSubmitPolicy(QDataWidgetMap per.ManualSubmit)
self.supplierMapper.setModel(self.suppliersModel)

fifth
2nd May 2008, 20:46
The order of your global constants must be the same as the creation order ofthe fields in your table. Also make sure you do not miss any fields in the declaration of your constants.

The range you are defining is just allocating numbers to the variables which will correspond to the fields of you database.

peterjb31
2nd May 2008, 22:31
Many thanks. Was wondering if you might be able to help with another question.

I have multiple tables as previously mentioned. I want to load data from one table into a QLineEdit on a certain form based on the relationship. At the moment the relationship is created using a ComboBox and the following code:


stockRelationModel = self.stockModel.relationModel(STOCKSUPPLIERID)
self.stockSupplierNameComboxBox.setModel(stockRela tionModel)
self.stockSupplierNameComboxBox.setModelColumn(
stockRelationModel.fieldIndex("companyName"))
self.stockMapper.addMapping(self.stockSupplierName ComboxBox, STOCKSUPPLIERID)

Do you know how I can load other data from the table based on the STOCKSUPPLIERID variable. The other option would be if I could get it to load a form at the record specified by that ID.

Can anyone give any help.