简体   繁体   English

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

[英]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. 在开始之前,我必须声明我只是一名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. 我正在为客户端使用Python和PyQt4构建医院系统,该系统通过API与基于Django的服务器进行通信。 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 eg patient_registration, triage, doctors_desk etc. 系统是基于角色的,因此客户端为每个角色(例如,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. 在数据库中,我有一个表Patient_queue处理这些记录。 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? 在表中显示当前信息非常简单,但是,我应该如何使添加到Patient_queue表中的任何新记录自动出现在医生队列中? 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. 谢谢。

you can use pyqt QSqlTableModel and it can be used as source to widgets like treeview, tableview. 您可以使用pyqt QSqlTableModel ,它可以用作诸如Treeview, TableView之类的小部件的源代码。 First create a database connection. 首先创建一个数据库连接。 eg sqlite: 例如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. 在这里我用了tableview。 You can use other views such as treeview. 您可以使用其他视图,例如treeview。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM