如何从db PyQt4获取“实时”数据

时间:2022-11-08 15:23:02

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.

在开始之前,我必须提交我只是一个中级Python开发人员,所以我希望我不会收到任何反对我的问题。

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.

我正在为客户端使用Python和PyQt4构建医院系统,它通过API与基于Django的服务器进行通信。多个客户端将与服务器通信。系统是基于角色的,因此客户端为每个角色显示不同的界面,例如patient_registration,triage,doctors_desk等。

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??

我正在努力解决的问题是如何处理患者的排队问题。每位医生都应该能够从他/她的办公桌上查看排队的病人。在db中,我有一个表patient_queue来处理这些记录。显示当前表中的信息是非常简单的,但是,我应该如何将添加到patient_queue表中的任何新记录自动显示在医生队列中?如何确保医生从数据库中获取最新数据,而不必像定期查询一样做些什么?

Thank you.

谢谢。

1 个解决方案

#1


0  

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

你可以使用pyqt QSqlTableModel,它可以用作树视图,tableview等小部件的源代码。首先创建一个数据库连接。例如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.

在这里我使用tableview。您可以使用其他视图,例如treeview。

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

#1


0  

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

你可以使用pyqt QSqlTableModel,它可以用作树视图,tableview等小部件的源代码。首先创建一个数据库连接。例如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.

在这里我使用tableview。您可以使用其他视图,例如treeview。

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