42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""DocumentCategory 文档分类模型。"""
|
||
|
||
from sqlalchemy import ForeignKey, Integer, String
|
||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
||
from app.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin
|
||
|
||
|
||
class DocumentCategory(UUIDPrimaryKeyMixin, TimestampMixin, Base):
|
||
"""文档分类模型。
|
||
|
||
技术审查 §2.2:document_categories 表。
|
||
"""
|
||
|
||
__tablename__ = "document_categories"
|
||
|
||
knowledge_base_id: Mapped[str] = mapped_column(
|
||
String(32),
|
||
ForeignKey("knowledge_bases.id"),
|
||
nullable=False,
|
||
index=True,
|
||
comment="所属知识库 ID",
|
||
)
|
||
name: Mapped[str] = mapped_column(
|
||
String(255),
|
||
nullable=False,
|
||
comment="分类名称",
|
||
)
|
||
sort_order: Mapped[int] = mapped_column(
|
||
Integer,
|
||
default=0,
|
||
nullable=False,
|
||
comment="排序序号",
|
||
)
|
||
|
||
# 关系
|
||
knowledge_base = relationship("KnowledgeBase", back_populates="categories", lazy="selectin")
|
||
documents = relationship("Document", back_populates="category", lazy="selectin")
|
||
|
||
def __repr__(self) -> str:
|
||
return f"<DocumentCategory {self.name!r} (kb={self.knowledge_base_id!r})>"
|