mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-25 13:51:04 +00:00
1. 统一移动代码生成模板到根目录templates目录,删除旧模板文件 2. 调整SQLAlchemy导入顺序,优化代码格式 3. 重构查询参数类,复用BaseQueryParam基础能力 4. 新增发票管理模块:添加weasyprint依赖,实现本地PDF发票渲染 5. 完善邮件、菜单等模块的代码实现与注释 6. 修复SQL查询条件写法,使用is_(True)替代==True 7. 补全模型类的UserMixin、TenantMixin继承与配置
88 lines
3.8 KiB
Django/Jinja
88 lines
3.8 KiB
Django/Jinja
# -*- coding: utf-8 -*-
|
|
|
|
{% if table.sub %}
|
|
from typing import List
|
|
{% endif %}
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
from fastapi import Query
|
|
{% for import_stmt in schema_import_list %}
|
|
{{ import_stmt }}
|
|
{% endfor %}
|
|
{# DateTimeStr 由 schema_import_list 在存在 created_time/updated_time 列时注入 #}
|
|
from app.common.enums import QueueEnum
|
|
from app.core.base_schema import BaseSchema, UserBySchema
|
|
|
|
class {{ class_name }}CreateSchema(BaseModel):
|
|
"""
|
|
{{ function_name }}新增模型
|
|
"""
|
|
{% for column in columns %}
|
|
{% if column.column_name not in ['uuid', 'created_time', 'updated_time', 'created_id', 'updated_id', 'is_deleted', 'deleted_time', 'deleted_id'] and column.column_name != pk_column_name %}
|
|
{% if column.column_name == 'status' %}
|
|
{{ column.column_name }}: {{ column.python_type }} = Field(default="0", description='{{ column.column_comment }}')
|
|
{% elif column.column_name == 'description' %}
|
|
{{ column.column_name }}: str | None = Field(default=None, max_length=255, description='{{ column.column_comment }}')
|
|
{% else %}
|
|
{{ column.column_name }}: {{ column.python_type }} = Field(default=..., description='{{ column.column_comment }}')
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
|
|
class {{ class_name }}UpdateSchema({{ class_name }}CreateSchema):
|
|
"""
|
|
{{ function_name }}更新模型
|
|
"""
|
|
...
|
|
|
|
|
|
class {{ class_name }}OutSchema({{ class_name }}CreateSchema, BaseSchema, UserBySchema):
|
|
"""
|
|
{{ function_name }}响应模型
|
|
"""
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class {{ class_name }}QueryParam:
|
|
"""{{ function_name }}查询参数"""
|
|
|
|
def __init__(
|
|
self,
|
|
{% for column in columns %}
|
|
{% if column.is_query and column.query_type == 'LIKE' %}
|
|
{{ column.column_name }}: str | None = Query(None, description="{{ column.column_comment }}"),
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% for column in columns %}
|
|
{% if column.is_query and column.query_type == 'EQ' and column.column_name not in ['created_time', 'updated_time'] %}
|
|
{{ column.column_name }}: {{ column.python_type }} | None = Query(None, description="{{ column.column_comment }}"),
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% if 'created_time' in table_column_names %}
|
|
created_time: list[DateTimeStr] | None = Query(None, description="创建时间范围", examples=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
|
|
{% endif %}
|
|
{% if 'updated_time' in table_column_names %}
|
|
updated_time: list[DateTimeStr] | None = Query(None, description="更新时间范围", examples=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
|
|
{% endif %}
|
|
) -> None:
|
|
{% for column in columns %}
|
|
{% if column.is_query and column.query_type == 'LIKE' %}
|
|
# 模糊查询字段
|
|
self.{{ column.column_name }} = (QueueEnum.like.value, {{ column.column_name }})
|
|
{% elif column.is_query and column.query_type == 'EQ' and column.column_name not in ['created_time', 'updated_time'] %}
|
|
# 精确查询字段
|
|
if {{ column.column_name }} is not None:
|
|
self.{{ column.column_name }} = (QueueEnum.eq.value, {{ column.column_name }})
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% if 'created_time' in table_column_names %}
|
|
# 时间范围查询
|
|
if created_time and len(created_time) == 2:
|
|
self.created_time = (QueueEnum.between.value, (created_time[0], created_time[1]))
|
|
{% endif %}
|
|
{% if 'updated_time' in table_column_names %}
|
|
if updated_time and len(updated_time) == 2:
|
|
self.updated_time = (QueueEnum.between.value, (updated_time[0], updated_time[1]))
|
|
{% endif %}
|
|
{# created_id / updated_id 若为 EQ 查询列,已在上方 query_type 循环中处理 #}
|