You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.2 KiB
Python

from sqlalchemy import ForeignKey, Integer, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.core.base_model import ModelMixin, TenantMixin, UserMixin
class EnergyReportVariableModel(ModelMixin, TenantMixin, UserMixin):
"""能源报告变量-章节关联模型。"""
__tablename__: str = "energy_report_variable"
__table_args__ = (UniqueConstraint("tenant_id", "template_id", "variable_name", "chapter_name"), {"comment": "能源报告变量章节关联表"})
__loader_options__: list[str] = [
"template",
"created_by",
"updated_by",
"deleted_by",
"tenant_by",
]
template_id: Mapped[int] = mapped_column(
Integer,
ForeignKey("energy_report_template.id", ondelete="CASCADE", onupdate="CASCADE"),
nullable=False,
index=True,
comment="能源报告模板ID",
)
variable_name: Mapped[str] = mapped_column(String(128), nullable=False, comment="变量名称")
chapter_name: Mapped[str] = mapped_column(String(128), nullable=False, comment="章节名称", index=True)
template = relationship("EnergyReportTemplateModel", lazy="selectin", foreign_keys=[template_id], uselist=False)