Files
dpb/backend/app/api/v1/module_bre/trait_observation/model.py
T
34047007@qq.com b95053c52c init: 初始化 dpb 桃育种系统代码库
前后端 + 后端 FastAPI 全量源码、部署脚本与文档。
2026-08-06 00:17:49 +08:00

61 lines
2.4 KiB
Python

"""性状观测 数据模型"""
from datetime import datetime
from sqlalchemy import Float, ForeignKey, Index, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.core.base_model import MappedBase, ModelMixin, UserMixin
class TraitObservationModel(ModelMixin, UserMixin, MappedBase):
"""性状观测 主数据表。"""
__tablename__ = "bre_trait_observation"
evaluation_id: Mapped[int] = mapped_column(
Integer, ForeignKey("bre_tree_evaluation.id", ondelete="CASCADE"),
index=True, nullable=True, comment="所属鉴定"
)
tree_id: Mapped[int] = mapped_column(
Integer, ForeignKey("bre_tree.id", ondelete="CASCADE"),
index=True, nullable=True, comment="单株"
)
combination_id: Mapped[int] = mapped_column(
Integer, ForeignKey("bre_cross_combination.id", ondelete="CASCADE"),
index=True, nullable=True, comment="杂交组合"
)
trait_id: Mapped[int] = mapped_column(
Integer, ForeignKey("bre_trait.id", ondelete="CASCADE"),
index=True, nullable=False, comment="性状"
)
evaluate_year: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="观测年份", default=None)
value_numeric: Mapped[float | None] = mapped_column(Float, nullable=True, comment="数值", default=None)
value_text: Mapped[str | None] = mapped_column(String(255), nullable=True, comment="文本值", default=None)
value_date: Mapped[str | None] = mapped_column(String(20), nullable=True, comment="日期值", default=None)
remark: Mapped[str | None] = mapped_column(Text, nullable=True, comment="备注", default=None)
trial_study_id: Mapped[int | None] = mapped_column(
Integer, ForeignKey("bre_trial_study.id", ondelete="SET NULL"),
index=True, nullable=True, comment="所属试验/站点(MET)"
)
crop_load: Mapped[float | None] = mapped_column(Float, nullable=True, comment="负载量(协变量)")
stage: Mapped[str | None] = mapped_column(
String(16), nullable=True, comment="观测发育阶段(juvenile幼龄/evaluation成株,缺省继承bre_trait.stage)"
)
# 无 status 列:覆盖基类默认 ix_<表>_status_deleted 索引,
# 仅保留 (created_time, is_deleted) 复合索引用于数据权限过滤。
__table_args__ = (
Index("ix_bre_trait_observation_created_deleted", "created_time", "is_deleted"),
)