23 lines
730 B
Python
23 lines
730 B
Python
"""Category model."""
|
|
|
|
from sqlalchemy import Column, String, Integer, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from app.models.base import Base, TimestampMixin
|
|
|
|
|
|
class Category(Base, TimestampMixin):
|
|
"""Category model."""
|
|
|
|
__tablename__ = "categories"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String(100), unique=True, nullable=False)
|
|
parent_id = Column(Integer, ForeignKey("categories.id", ondelete="SET NULL"))
|
|
|
|
# Relationships
|
|
subcategories = relationship("Category", backref="parent", remote_side=[id])
|
|
tickets = relationship("Ticket", back_populates="category")
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Category(id={self.id}, name='{self.name}')>"
|