mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 20:55:14 +00:00
refactor(backend): 重构数据库模型和初始化逻辑 fix(frontend): 修复权限指令在多个组件中的使用问题 perf(backend): 优化数据库连接和初始化性能 docs: 更新低代码生成器的README文档 style: 清理无用代码和注释 chore: 移除不再需要的依赖项 test: 更新用户权限相关测试用例 ci: 更新CI配置以支持新的权限检查 build: 更新依赖项版本
45 lines
1.7 KiB
Django/Jinja
45 lines
1.7 KiB
Django/Jinja
# -*- 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 {{ tableName|snake_to_pascal_case }}Model(CreatorMixin):
|
|
"""
|
|
{{ functionName }}
|
|
"""
|
|
|
|
__tablename__ = '{{ tableName }}'
|
|
|
|
__table_args__ = {'comment': '{{ functionName }}'}
|
|
|
|
{% for column in columns %}
|
|
{{ column.columnName }}: Mapped[Optional[{{ column.pythonType }}]] = mapped_column({{ column.columnType|get_sqlalchemy_type }}, nullable=True, comment='{{ column.columnComment }}')
|
|
{% endfor %}
|
|
|
|
def __repr__(self):
|
|
return f"<{{ tableName|snake_to_pascal_case }}Model(id={self.id})>"
|
|
|
|
{% if subTable %}
|
|
|
|
class {{ subClassName }}(Base):
|
|
"""
|
|
{{ subTable.function_name }}表
|
|
"""
|
|
__tablename__ = '{{ subTableName }}'
|
|
|
|
__table_args__ = {'comment': '{{ subTable.function_name }}'}
|
|
|
|
{% for column in subTable.columns %}
|
|
{{ column.column_name }}: Mapped[Optional[{{ column.python_type }}]] = mapped_column({{ column.column_type | get_sqlalchemy_type }}, {% if column.column_name == subTableFkName %}ForeignKey('{{ tableName }}.id'), {% endif %}{% if column.pk %}primary_key=True, {% endif %}nullable=True, comment='{{ column.column_comment }}')
|
|
{% endfor %}
|
|
|
|
{{ tableName }} = relationship('{{ tableName|snake_to_pascal_case }}Model', back_populates='{{ subTable.table_name }}_list')
|
|
|
|
{{ tableName|snake_to_pascal_case }}Model.{{ subTable.table_name }}_list = relationship('{{ subClassName }}', back_populates='{{ tableName }}')
|
|
|
|
{% endif %} |