ifixkart-backend/app/models/CategoryModel.py

25 lines
1.3 KiB
Python

from sqlalchemy import Column, String, Boolean, DateTime, ForeignKey
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.core.database.db_session import Base
class Category(Base):
__tablename__ = "categories"
category_id = Column(String(26), primary_key=True)
parent_category_id = Column(String(26), ForeignKey("categories.category_id", ondelete="SET NULL"), nullable=True)
name = Column(String(100), nullable=False)
slug = Column(String(100), unique=True, nullable=False)
description = Column(String(500), nullable=True)
image_url = Column(String(500), nullable=True)
sort_order = Column(String(10), default="0")
is_parent_feature = Column(Boolean, default=False, nullable=False)
is_active = Column(Boolean, default=True)
# CMS-driven display controls
show_in_sidebar = Column(Boolean, default=True, nullable=False)
mega_group = Column(String(64), nullable=True) # e.g. "smartphones", "laptops"
badge = Column(String(32), nullable=True) # e.g. "HOT", "NEW", "SALE"
created_at = Column(DateTime, server_default=func.now())
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
parent = relationship("Category", remote_side=[category_id], backref="children")