Wedava
Wedava

Reputation: 1231

How to get 'real-time' data from db PyQt4

Before I start, I must submit that I am just an intermediate Python developer and so I hope I will not receive any backlash for my question.

I'm building a hospital system using Python and PyQt4 for the client side, which communicates with a Django based server through an API. Multiple clients will be communicating with the server. The system is role based and thus the client displays a different interface for each of the roles e.g patient_registration, triage, doctors_desk etc.

The problem i'm struggling with is how to handle the queuing of patients. Each doctor should be able to view the queued patients from his/her desk. In the db, I have a table patient_queue which handles those records. Displaying the info currently in the table is quite straightforward, however, how I'm I supposed to make any new record that is added to the patient_queue table to appear in the doctors' queue automatically? How can I ensure the doctors have the latest data from the db without having to do something hacky like making the query periodically??

Thank you.

Upvotes: 2

Views: 616

Answers (1)

amg
amg

Reputation: 45

you can use pyqt QSqlTableModel and it can be used as source to widgets like treeview, tableview. First create a database connection. eg sqlite:

db = QtSql.QSqlDatabase.addDatabase('QSQLITE')
db.setDatabaseName('database_name.db')
model = QtSql.QSqlTableModel()
model.setTable('database_table_name')
model.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit)
model.select()  

Here i used tableview. You can use other views such as treeview.

self.tableView = QtGui.QTableView()
self.tableView.setModel(self.model)

Upvotes: 1

Related Questions