load project
This commit is contained in:
54
backend/app/models/template.py
Normal file
54
backend/app/models/template.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class DocumentTemplate(Base):
|
||||
__tablename__ = "document_templates"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
name: Mapped[str] = mapped_column(String(255))
|
||||
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
original_filename: Mapped[str] = mapped_column(String(255))
|
||||
file_path: Mapped[str] = mapped_column(String(512))
|
||||
owner_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
|
||||
is_public: Mapped[bool] = mapped_column(default=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
|
||||
)
|
||||
|
||||
owner = relationship("User", back_populates="templates")
|
||||
variables = relationship(
|
||||
"TemplateVariable",
|
||||
back_populates="template",
|
||||
cascade="all, delete-orphan",
|
||||
order_by="TemplateVariable.order",
|
||||
)
|
||||
documents = relationship(
|
||||
"FilledDocument",
|
||||
back_populates="template",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
|
||||
class TemplateVariable(Base):
|
||||
__tablename__ = "template_variables"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
template_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("document_templates.id", ondelete="CASCADE")
|
||||
)
|
||||
name: Mapped[str] = mapped_column(String(255))
|
||||
label: Mapped[str] = mapped_column(String(255))
|
||||
field_type: Mapped[str] = mapped_column(String(50))
|
||||
default_value: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
is_required: Mapped[bool] = mapped_column(default=True)
|
||||
order: Mapped[int] = mapped_column(Integer, default=0)
|
||||
parent_variable: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
style_params: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
template = relationship("DocumentTemplate", back_populates="variables")
|
||||
Reference in New Issue
Block a user