30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
from uuid import uuid4
|
|
|
|
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class Category(Base):
|
|
__tablename__ = "categories"
|
|
|
|
id = Column(String(36), primary_key=True, default=lambda: str(uuid4()))
|
|
name = Column(String(100), nullable=False, index=True)
|
|
slug = Column(String(120), nullable=False, unique=True)
|
|
description = Column(Text, nullable=True)
|
|
image = Column(String(255), nullable=True)
|
|
parent_id = Column(String(36), ForeignKey("categories.id"), nullable=True)
|
|
is_active = Column(Boolean, default=True)
|
|
display_order = Column(Integer, default=0)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Relationships
|
|
parent = relationship("Category", remote_side=[id], backref="subcategories")
|
|
products = relationship("Product", back_populates="category")
|
|
|
|
def __repr__(self):
|
|
return f"<Category {self.name}>"
|