mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 13:05:18 +00:00
移除不必要的配置字段如作者、模板类型等,优化字段初始化逻辑 重构模板生成逻辑,移除主子表和树表模板支持 优化前端代码生成页面,简化配置步骤和表单验证 更新文档中的代码生成模块说明和快速开始指南
62 lines
1.9 KiB
Django/Jinja
62 lines
1.9 KiB
Django/Jinja
# -*- coding:utf-8 -*-
|
||
|
||
{% set pkField = pk_column.python_field %}
|
||
{% set pk_field = pk_column.python_field | camel_to_snake %}
|
||
{% set pkParentheseIndex = pk_column.column_comment.find("(") %}
|
||
{% set pk_field_comment = pk_column.column_comment[:pkParentheseIndex] if pkParentheseIndex != -1 else pk_column.column_comment %}
|
||
{% set vo_field_required = namespace(has_required=False) %}
|
||
{% set vo_field_daterange = namespace(has_daterange=False) %}
|
||
{% for column in columns %}
|
||
{% if column.required %}
|
||
{% set vo_field_required.has_required = True %}
|
||
{% endif %}
|
||
{% if column.html_type == "datetime" and column.query_type == "BETWEEN" %}
|
||
{% set vo_field_daterange.has_daterange = True %}
|
||
{% endif %}
|
||
{% endfor %}
|
||
{% set sub_vo_field_required = namespace(has_required=False) %}
|
||
{% if table.sub %}
|
||
{% for sub_column in subTable.columns %}
|
||
{% if sub_column.required %}
|
||
{% set sub_vo_field_required.has_required = True %}
|
||
{% endif %}
|
||
{% endfor %}
|
||
{% endif %}
|
||
{% for vo_import in vo_import_list %}
|
||
{{ vo_import }}
|
||
{% endfor %}
|
||
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
||
|
||
{% if table.sub %}
|
||
from typing import List, Optional
|
||
{% else %}
|
||
from typing import Optional
|
||
{% endif %}
|
||
|
||
from app.core.base_schema import BaseSchema
|
||
|
||
class {{ class_name }}CreateSchema(BaseModel):
|
||
"""
|
||
{{ function_name }}新增模型
|
||
"""
|
||
|
||
{% for column in columns %}
|
||
{% if column.column_name not in ['id', 'creator_id', 'created_at', 'updated_at'] %}
|
||
{{ column.column_name }}: Optional[{{ column.python_type }}] = Field(default=None, description='{{ column.column_comment }}')
|
||
{% endif %}
|
||
{% endfor %}
|
||
|
||
|
||
class {{ class_name }}UpdateSchema({{ class_name }}CreateSchema):
|
||
"""
|
||
{{ function_name }}更新模型
|
||
"""
|
||
...
|
||
|
||
|
||
class {{ class_name }}OutSchema({{ class_name }}CreateSchema, BaseSchema):
|
||
"""
|
||
{{ function_name }}响应模型
|
||
"""
|
||
model_config = ConfigDict(from_attributes=True)
|