Files
writer-ide/backend/models/document.py
T
admin 46af290db3
Build and Push Docker Images / build-and-push (push) Failing after 3m33s
initial commit
2026-11-07 16:39:43 +03:00

52 lines
1.5 KiB
Python

from datetime import datetime
from typing import Optional
from uuid import uuid4
from pydantic import BaseModel, Field
class DocumentNode(BaseModel):
"""Иерархическая модель документа: Книга → Глава → Сцена"""
id: str = Field(default_factory=lambda: str(uuid4()))
project_id: str
parent_id: Optional[str] = None
title: str = Field(..., min_length=1, max_length=200)
content: str = ""
type: str = Field(default="scene", pattern="^(book|chapter|scene)$")
order: int = 0
created_at: str = Field(default_factory=lambda: datetime.now().isoformat())
updated_at: str = Field(default_factory=lambda: datetime.now().isoformat())
# --- Модели для обратной совместимости (старый плоский формат) ---
class DocumentBase(BaseModel):
"""Базовая модель документа (legacy)"""
title: str = Field(..., min_length=1, max_length=200)
content: str = ""
type: str = Field(default="scene", pattern="^(scene|chapter|bible)$")
class DocumentCreate(DocumentBase):
"""Модель для создания нового документа (legacy)"""
pass
class DocumentUpdate(BaseModel):
"""Модель для обновления контента документа (legacy)"""
content: str
class DocumentResponse(DocumentBase):
"""Модель ответа с документом (legacy)"""
id: str
class Config:
from_attributes = True