mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 04:46:26 +00:00
feat(代码生成器): 重构代码生成模板并增强安全性
重构代码生成模板结构,将模板文件移动到标准目录 添加文件覆盖控制和安全路径检查,防止生成到项目外 优化生成逻辑,支持跳过已存在文件并返回统计信息 完善模板内容,增加分页查询和更多功能实现细节
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from sqlalchemy import String, Integer, Text, DateTime
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.base_model import CreatorMixin
|
||||
|
||||
|
||||
class {{ table_name|snake_to_pascal_case }}Model(CreatorMixin):
|
||||
"""
|
||||
{{ function_name }}表
|
||||
"""
|
||||
|
||||
__tablename__ = '{{ table_name }}'
|
||||
__table_args__ = {'comment': '{{ function_name }}'}
|
||||
|
||||
{% for column in columns %}
|
||||
{{ column.column_name }}: Mapped[Optional[{{ column.python_type }}]] = mapped_column({{ column.column_type|get_sqlalchemy_type }}, nullable=True, comment='{{ column.column_comment }}')
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% if sub_table %}
|
||||
|
||||
class {{ sub_class_name }}(Base):
|
||||
"""
|
||||
{{ sub_table.function_name }}表
|
||||
"""
|
||||
__tablename__ = '{{ sub_table_name }}'
|
||||
__table_args__ = {'comment': '{{ sub_table.function_name }}'}
|
||||
|
||||
{% for column in sub_table.columns %}
|
||||
{{ column.column_name }}: Mapped[Optional[{{ column.python_type }}]] = mapped_column({{ column.column_type | get_sqlalchemy_type }}, {% if column.column_name == sub_table_fk_name %}ForeignKey('{{ table_name }}.id'), {% endif %}{% if column.pk %}primary_key=True, {% endif %}nullable=True, comment='{{ column.column_comment }}')
|
||||
{% endfor %}
|
||||
|
||||
{{ table_name }} = relationship('{{ table_name|snake_to_pascal_case }}Model', back_populates='{{ sub_table.table_name }}_list')
|
||||
|
||||
{{ table_name|snake_to_pascal_case }}Model.{{ sub_table.table_name }}_list = relationship('{{ sub_class_name }}', back_populates='{{ table_name }}')
|
||||
|
||||
{% endif %}
|
||||
Reference in New Issue
Block a user