Files
amb_rag/backend/app/models/document_category.py
T
2026-09-01 12:24:43 +08:00

42 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""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})>"