
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
23 lines
980 B
Python
23 lines
980 B
Python
from datetime import datetime
|
|
from sqlalchemy import Column, String, Float, Integer, DateTime, Text, ForeignKey, Boolean
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class Product(Base):
|
|
id = Column(String, primary_key=True, index=True)
|
|
name = Column(String, index=True)
|
|
description = Column(Text, nullable=True)
|
|
price = Column(Float, nullable=False)
|
|
stock = Column(Integer, nullable=False, default=0)
|
|
is_active = Column(Boolean, default=True)
|
|
category_id = Column(String, ForeignKey("category.id"))
|
|
image_url = Column(String, nullable=True)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Relationships
|
|
category = relationship("Category", back_populates="products")
|
|
order_items = relationship("OrderItem", back_populates="product")
|
|
cart_items = relationship("CartItem", back_populates="product") |