ервый импорт проекта
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
"""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}')>"
|
||||
Reference in New Issue
Block a user