rename grocery to product
This commit is contained in:
@@ -6,19 +6,19 @@ from datetime import datetime
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
# Association table for many-to-many relationship between shopping events and groceries
|
||||
shopping_event_groceries = Table(
|
||||
'shopping_event_groceries',
|
||||
# Association table for many-to-many relationship between shopping events and products
|
||||
shopping_event_products = Table(
|
||||
'shopping_event_products',
|
||||
Base.metadata,
|
||||
Column('id', Integer, primary_key=True, autoincrement=True), # Artificial primary key
|
||||
Column('shopping_event_id', Integer, ForeignKey('shopping_events.id'), nullable=False),
|
||||
Column('grocery_id', Integer, ForeignKey('groceries.id'), nullable=False),
|
||||
Column('amount', Float, nullable=False), # Amount of this grocery bought in this event
|
||||
Column('price', Float, nullable=False) # Price of this grocery at the time of this shopping event
|
||||
Column('product_id', Integer, ForeignKey('products.id'), nullable=False),
|
||||
Column('amount', Float, nullable=False), # Amount of this product bought in this event
|
||||
Column('price', Float, nullable=False) # Price of this product at the time of this shopping event
|
||||
)
|
||||
|
||||
class Grocery(Base):
|
||||
__tablename__ = "groceries"
|
||||
class Product(Base):
|
||||
__tablename__ = "products"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String, nullable=False, index=True)
|
||||
@@ -30,7 +30,7 @@ class Grocery(Base):
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
|
||||
# Relationships
|
||||
shopping_events = relationship("ShoppingEvent", secondary=shopping_event_groceries, back_populates="groceries")
|
||||
shopping_events = relationship("ShoppingEvent", secondary=shopping_event_products, back_populates="products")
|
||||
|
||||
class Shop(Base):
|
||||
__tablename__ = "shops"
|
||||
@@ -58,4 +58,4 @@ class ShoppingEvent(Base):
|
||||
|
||||
# Relationships
|
||||
shop = relationship("Shop", back_populates="shopping_events")
|
||||
groceries = relationship("Grocery", secondary=shopping_event_groceries, back_populates="shopping_events")
|
||||
products = relationship("Product", secondary=shopping_event_products, back_populates="shopping_events")
|
||||
Reference in New Issue
Block a user