PyQt表小部件从表和数据库中删除选定的行

2024-06-28 11:19:57 发布

您现在位置:Python中文网/ 问答频道 /正文

enter image description here

enter image description here

我需要这几行代码的帮助。我想选择一行并从数据库中删除表中的行。在

def deleteProduct(self):

    row = self.products_table.currentRow()

    if row > -1:
        currentproductid = (self.products_table.item(row, 0).text(), )
        query = session.query(Product).filter(Product.product_id==currentproductid).first()
        session.delete(query)
        session.commit()

        self.mainTable.removeRow(currentRow)

我得到了这个错误:

^{pr2}$

Tags: 代码self数据库ifsessiondeftableproduct
1条回答
网友
1楼 · 发布于 2024-06-28 11:19:57
    def deleteProduct(self):
        row = self.products_table.currentRow()

        currentproductid = (self.products_table.item(row, 0).text() )
        product_name = (self.products_table.item(row, 1).text() )
        query = session.query(Product).filter(Product.product_id==str(currentproductid)).first()
        session.delete(query)
        session.commit()
        self.products_table.removeRow(row)

相关问题 更多 >