
- Fixed circular import issue between base.py and base_class.py - Updated base_class.py to define Base directly and import models - Refactored base.py to import Base from base_class.py - Updated all models to import Base from base_class.py - Enhanced error handling in migrations/env.py to catch ImportError
23 lines
832 B
Python
23 lines
832 B
Python
from datetime import datetime
|
|
from sqlalchemy import Column, DateTime, Float, Integer, String, Text
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class Product(Base):
|
|
__tablename__ = "products"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, index=True, nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
price = Column(Float, nullable=False)
|
|
stock = Column(Integer, default=0, nullable=False)
|
|
image_url = Column(String, nullable=True)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Relationships
|
|
order_items = relationship("OrderItem", back_populates="product")
|
|
cart_items = relationship("CartItem", back_populates="product")
|