Files
111 998211c483 feat: 初始化考培练系统项目
- 从服务器拉取完整代码
- 按框架规范整理项目结构
- 配置 Drone CI 测试环境部署
- 包含后端(FastAPI)、前端(Vue3)、管理端

技术栈: Vue3 + TypeScript + FastAPI + MySQL
2026-01-24 19:33:28 +08:00

48 lines
1.5 KiB
Python
Raw Permalink 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.
"""基础模型定义"""
from datetime import datetime
from typing import Optional
from sqlalchemy import Column, DateTime, Integer, Boolean, func
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Mapped, mapped_column
# 创建基础模型类
Base = declarative_base()
class BaseModel(Base):
"""
基础模型类,所有模型都应继承此类
包含通用字段id, created_at, updated_at
时区使用北京时间Asia/Shanghai, UTC+8
"""
__abstract__ = True
__allow_unmapped__ = True # SQLAlchemy 2.0 兼容性
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
created_at: Mapped[datetime] = mapped_column(
DateTime, server_default=func.now(), nullable=False, comment="创建时间(北京时间)"
)
updated_at: Mapped[datetime] = mapped_column(
DateTime, server_default=func.now(), onupdate=func.now(), nullable=False, comment="更新时间(北京时间)"
)
class SoftDeleteMixin:
"""软删除混入类"""
__allow_unmapped__ = True
is_deleted: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
deleted_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
class AuditMixin:
"""审计字段混入类"""
__allow_unmapped__ = True
created_by: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
updated_by: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)