
Create a complete e-commerce application with the following features: - User authentication and authorization - Product and category management - Shopping cart functionality - Order processing - Database migrations with Alembic - Comprehensive documentation
19 lines
800 B
Python
19 lines
800 B
Python
from datetime import datetime
|
|
from sqlalchemy import Column, String, Float, Integer, DateTime, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class OrderItem(Base):
|
|
id = Column(String, primary_key=True, index=True)
|
|
order_id = Column(String, ForeignKey("order.id"))
|
|
product_id = Column(String, ForeignKey("product.id"))
|
|
quantity = Column(Integer, nullable=False, default=1)
|
|
price = Column(Float, nullable=False) # Price at the time of purchase
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Relationships
|
|
order = relationship("Order", back_populates="items")
|
|
product = relationship("Product", back_populates="order_items") |