List of data in SQL database

Viewed 21

My system simulates a company with stores, and each store should have an inventory of its items. I'd like to have each store model stored in the database have a list of items. What I currently have isn't providing me what I need. Do I need to create a new Python Object called Inventory that holds a List of Items and make that a Column, (is this even possible) or do I need to do something else?

from sqlalchemy import Column, ForeignKey, Integer, String, Float

from sqlalchemy.orm import relationship

from database import Base

class Item(Base):
    __tablename__ = "items"

    item_id = Column(Integer, primary_key=True, index=True)
    name = Column(String)
    price = Column(Float)
    quantity = Column(Integer)

    stores = relationship("Store", back_populates="inventory")

class Store(Base):
    __tablename__ = "stores"

    store_id = Column(Integer, primary_key=True, index=True)
    store_name = Column(String)
    
    inventory = relationship("Item", back_populates="stores")
    item_id = Column(Integer, ForeignKey("items.item_id"))

    phone = Column(String)
    email = Column(String)
0 Answers
Related