/
tsps
/
core
Обзор
Документация
Войти
/
tsps
/
core
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
app/models/document.py
34 строки
2 KB
Василий Петров
Просмотр документа
23 фев 2026, 21:23
23 фев 2026, 21:23
88c3ec6
Код
Авторство
О чём код?
from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, UniqueConstraint, Date from sqlalchemy.orm import relationship from sqlalchemy.sql import func from app.database import Base class Document(Base): __tablename__ = "document" id = Column(Integer, primary_key=True) title = Column(String(500), nullable=True) date = Column(Date, nullable=True) type_id = Column(Integer, ForeignKey("document_type.id"), nullable=False) case_entity_id = Column(Integer, ForeignKey("case_entity.id"), nullable=False) judge_id = Column(Integer, ForeignKey("judge.id"), nullable=False) court_id = Column(Integer, ForeignKey("court.id"), nullable=False) text = Column(Text, nullable=True) text_extracted_at = Column(DateTime, nullable=True) created_at = Column(DateTime, server_default=func.now(), nullable=False) updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False) # Связи с сущностями type = relationship("DocumentType", back_populates="documents") case_entity = relationship("CaseEntity", back_populates="documents") judge = relationship("Judge", back_populates="documents") court = relationship("Court", back_populates="documents") document_file = relationship("DocumentFile", back_populates="document", uselist=False) # 1:1 # Номер дела + заголовок - должны быть уникальны __table_args__ = ( UniqueConstraint('title', 'case_entity_id', name='unique_title_case_entity'), ) def __repr__(self): return f"<Document(id={self.id}, title='{self.title[:30] if self.title else '—'}...')>"