Spaces:
Sleeping
Sleeping
Upload app/models/product.py
Browse files- app/models/product.py +56 -0
app/models/product.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime, timezone
|
| 2 |
+
|
| 3 |
+
from sqlalchemy import (
|
| 4 |
+
Column, Integer, String, Text, Float, DateTime,
|
| 5 |
+
ForeignKey, Boolean, Enum as SQLEnum,
|
| 6 |
+
)
|
| 7 |
+
from sqlalchemy.orm import relationship
|
| 8 |
+
import enum
|
| 9 |
+
|
| 10 |
+
from app.db.base import Base
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class Product(Base):
|
| 14 |
+
__tablename__ = "products"
|
| 15 |
+
|
| 16 |
+
id = Column(Integer, primary_key=True, autoincrement=True)
|
| 17 |
+
name_ar = Column(String(500), nullable=False)
|
| 18 |
+
name_en = Column(String(500), nullable=False)
|
| 19 |
+
description_ar = Column(Text, nullable=True)
|
| 20 |
+
description_en = Column(Text, nullable=True)
|
| 21 |
+
price = Column(Float, nullable=False)
|
| 22 |
+
compare_price = Column(Float, nullable=True)
|
| 23 |
+
stock = Column(Integer, default=0, nullable=False)
|
| 24 |
+
category_id = Column(Integer, ForeignKey("categories.id"), nullable=True)
|
| 25 |
+
rating = Column(Float, default=0.0, nullable=False)
|
| 26 |
+
rating_count = Column(Integer, default=0, nullable=False)
|
| 27 |
+
is_featured = Column(Boolean, default=False, nullable=False)
|
| 28 |
+
is_active = Column(Boolean, default=True, nullable=False)
|
| 29 |
+
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), nullable=False)
|
| 30 |
+
|
| 31 |
+
category = relationship("Category", back_populates="products")
|
| 32 |
+
images = relationship("ProductImage", back_populates="product", cascade="all, delete-orphan")
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class ProductImage(Base):
|
| 36 |
+
__tablename__ = "product_images"
|
| 37 |
+
|
| 38 |
+
id = Column(Integer, primary_key=True, autoincrement=True)
|
| 39 |
+
product_id = Column(Integer, ForeignKey("products.id", ondelete="CASCADE"), nullable=False)
|
| 40 |
+
image_url = Column(String(1000), nullable=False)
|
| 41 |
+
alt_text = Column(String(500), nullable=True)
|
| 42 |
+
sort_order = Column(Integer, default=0, nullable=False)
|
| 43 |
+
|
| 44 |
+
product = relationship("Product", back_populates="images")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class Category(Base):
|
| 48 |
+
__tablename__ = "categories"
|
| 49 |
+
|
| 50 |
+
id = Column(Integer, primary_key=True, autoincrement=True)
|
| 51 |
+
name_ar = Column(String(255), nullable=False)
|
| 52 |
+
name_en = Column(String(255), nullable=False)
|
| 53 |
+
icon = Column(String(50), nullable=True)
|
| 54 |
+
sort_order = Column(Integer, default=0, nullable=False)
|
| 55 |
+
|
| 56 |
+
products = relationship("Product", back_populates="category")
|