dingdanquanliucheng/backend/app/models/base.py
taiyi 34e9be8912 为 core 层和 models 层添加中文注释
- core: config、security、exceptions、responses、error_codes、db、main
- models: base、business(17个模型类)、system(6个模型类)、__init__
- 每个函数和类均标注作用、返回值、被调用方

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-30 06:57:21 +08:00

29 lines
840 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""ORM 模型公共 Mixin 定义。
提供时间戳和软删除等通用字段,被所有业务模型继承。
"""
from sqlalchemy import DateTime, func
from sqlalchemy.orm import Mapped, mapped_column
class TimestampMixin:
"""时间戳 Mixin自动维护 created_at 和 updated_at 字段。
created_at 由数据库服务器默认值设置updated_at 在每次更新时自动刷新。
"""
created_at: Mapped[DateTime] = mapped_column(DateTime, server_default=func.now())
updated_at: Mapped[DateTime] = mapped_column(
DateTime,
server_default=func.now(),
onupdate=func.now(),
)
class AuditMixin:
"""软删除 Mixindeleted=0 表示正常deleted=1 表示已删除。
查询时需手动过滤 deleted == 0。
"""
deleted: Mapped[int] = mapped_column(default=0)