第二步

This commit is contained in:
amb
2026-09-01 12:24:43 +08:00
parent 47bf6cc5ca
commit 1d8621717a
14 changed files with 815 additions and 9 deletions
+41
View File
@@ -0,0 +1,41 @@
"""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.2document_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})>"