Python Forum
PyQt, Open a Table when a row is selected populating it with the row values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyQt, Open a Table when a row is selected populating it with the row values
#11
(Dec-17-2018, 12:08 PM)Axel_Erfurt Wrote: You create the database yourself?
There is no database file to which you connect.

Yes, I have a file for that in user.py for the database.
here is the file.I mistakenly copied the wrong one-product.py

import sqlalchemy
from sqlalchemy import exists
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import DateTime,ForeignKey,Boolean
from sqlalchemy.orm import relationship,backref
from datetime import datetime
Base = declarative_base()

class User(Base):
    __tablename__   = 'users'   
    user_id     = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
    name            = sqlalchemy.Column(sqlalchemy.String(35), nullable=False)
    password        = sqlalchemy.Column(sqlalchemy.String(35), nullable=False)
    email           = sqlalchemy.Column(sqlalchemy.String(35))
    contact         = sqlalchemy.Column(sqlalchemy.String(50))

    def __repr__(self):
       return "<User(name='%s',password='%s',contact='%s', email='%s')>" % (self.name,self.password,self.contact, self.email)
    

class Product(Base):
    __tablename__   = 'products'   
    product_id     = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
    product_name            = sqlalchemy.Column(sqlalchemy.String(35), nullable=False)
    inventory_received      = sqlalchemy.Column(sqlalchemy.String(35), nullable=False)
    starting_inventory        = sqlalchemy.Column(sqlalchemy.String(35), nullable=False)
    inventory_on_hand           = sqlalchemy.Column(sqlalchemy.String(35))
    minimum_required         = sqlalchemy.Column(sqlalchemy.String(50))
    updated_on      = sqlalchemy.Column(DateTime(),default=datetime.now())
    Created_on =    sqlalchemy.Column(DateTime(),default=datetime.now())
    user    = relationship('User',backref=backref('products',order_by=product_id))
    user_id =   sqlalchemy.Column(sqlalchemy.Integer, ForeignKey('users.user_id'))

    def __repr__(self):
       return "<Product(product_name='%s',starting_inventory ='%s',inventory_received ='%s',inventory_on_hand='%s', minimum_required='%s')>" % (self.product_name,self.starting_inventory,self.inventory_on_hand, self.minimum_required,self.inventory_received)

    
 
engine = sqlalchemy.create_engine("sqlite:///user.db", echo='debug')
Base.metadata.create_all(engine)


DBsession = sqlalchemy.orm.sessionmaker(bind=engine) 
session = DBsession()
Reply
#12
Ok, it creates a database with no entries.

If there are entries then you want to fill the ComboBoxes? Or the table?

I have a DB Viewer on github that shows how to load a database into QTableWidget
Reply
#13
(Dec-17-2018, 07:15 PM)Axel_Erfurt Wrote: Ok, it creates a database with no entries.

If there are entries then you want to fill the ComboBoxes? Or the table?

I have a DB Viewer on github that shows how to load a database into QTableWidget
After the the comboBoxes are filled correctly it will saved in QtableWidget in the database.
There are entries in the database in QtableWidget.
The columns are product_id,product_name,inventory_received,starting_inventory,product_price and values for each rows.The content of my database user.db is shown in the file but I intended to add price.

I have three comboboxes
first comboBox is product id
second comboboxes is product_name
third comboBoxes is price.

I want the second Combobox to list all the product.That is working perfectly.
I want the first comboBox to reflect the product_id of the selected product_name.
I want the third comboBox to reflect the price of the selected product_name.
How can I achieve this behavior?I have checked out your work on GitHub.But, I am not getting the database to work on my side even when add a database on my system into the path.
Reply
#14
your user.db has no column for product price, you want get it from the tableWidget?
Reply
#15
Yes,I intend to add price to my table later but as I have said I need help on how to add items to my comboBoxes from the database such that once, I change value in( Product_name) one comboBox other comboBoxes(product_id) and possibly product_price will change into values in the database.I will update with full code later.
Reply
#16
You mean somethig like that?

video

Download Project
Reply
#17
No,I mean product_name_box will be a list of all products ,but when a pick a product like Maclean the product_id change to 1 and price to 200.Likewise for all other products.When I press value comboBox the first item is added to Cart Table.I have added a picture what I want.Really appreciate your effort Azel_Efurt.Once I get this basic features all other features can be added.
The table widget in the link is cart table
https://www.dropbox.com/s/qfou2iuyqw266l...M.png?dl=0
Reply
#18
(Dec-18-2018, 06:17 PM)Axel_Erfurt Wrote: You mean somethig like that?

video

Download Project

Thank so much.I can see your code so worked well.Thanks for the help.I will update with the other features.You have solved it.Thanks once again Azel_ErFurt and others.
Reply
#19
   
(Dec-19-2018, 06:23 PM)rarevesselt Wrote:
(Dec-18-2018, 06:17 PM)Axel_Erfurt Wrote: You mean somethig like that?

video

Download Project

Thank so much.I can see your code so worked well.Thanks for the help.I will update with the other features.You have solved it.Thanks once again Azel_ErFurt and others.

The image I added is what I end up having.But,I need help on it.When I changed the quantity of product from 1 to another number, I want the table to update automatically.How can I do that?
My second interest is how can I make multiple users to operate the UI simultaneously.

This is function I used;
    def your_function(self):
        self.row = self.Products_table.currentRow()
        self.currentproduct = (self.Products_table.item(self.row, 0).text() )
        self.currentprice = (self.Products_table.item(self.row,1).text() )
        ordereditems = QtGui.QTableWidgetItem()
        row = self.ordereditems.currentRow()
        numRows = self.ordereditems.rowCount()
        self.ordereditems.insertRow(numRows)
        self.total = 0.0
        self.items ={}
        self.ordereditems.setItem(numRows, 0, QtGui.QTableWidgetItem(self.currentproduct))
        self.ordereditems.setItem(numRows, 1, QtGui.QTableWidgetItem(str(self.currentprice)))
        self.ordereditems.setItem(numRows, 2, QtGui.QTableWidgetItem("1"))
        for numRows in range(numRows+1):
            self.ordereditems.setItem(numRows, 2, QtGui.QTableWidgetItem(str(self.currentquantity)))
            self.currentprice =float(self.ordereditems.item(numRows,1).text() )
            amount = float(self.currentprice) * float(self.currentquantity)
            self.ordereditems.setItem(numRows, 3, QtGui.QTableWidgetItem(str(amount)))
            self.total += amount
        self.totallinedit.setText(str(self.total))
        self.items = {str(self.currentproduct):self.currentquantity}
        self.items.update({str(self.currentproduct):self.currentquantity})
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] populating dropdown from Method mikisDW 2 3,814 Apr-06-2020, 08:06 PM
Last Post: mikisDW
  Populating a Listbox from db Query DT2000 2 6,432 Feb-25-2019, 05:45 PM
Last Post: DT2000
  PyQt Selected row in Table Widget rarevesselt 3 23,556 Dec-07-2018, 07:00 PM
Last Post: rarevesselt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020