mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 04:46:26 +00:00
1. 统一前端环境变量命名,新增通用项目标题配置 2. 修复后端接口参数绑定方式,将Depends改为Query适配FastAPI解析 3. 优化表格列排序、搜索过滤功能与页面布局样式 4. 重构路由与状态管理代码,移除循环依赖 5. 更新依赖版本与脚本命令,修复构建警告 6. 调整多语言文案与快捷入口配置 7. 修复通知中心样式与接口返回格式
53 lines
3.1 KiB
Django/Jinja
53 lines
3.1 KiB
Django/Jinja
# -*- coding: utf-8 -*-
|
|
|
|
{% for model_import in model_import_list %}
|
|
{{ model_import }}
|
|
{% endfor %}
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.core.base_model import ModelMixin, UserMixin
|
|
{% if table.sub and not is_sub_entity %}
|
|
from ..{{ sub_module_name }}.model import {{ sub_model_class_name }}
|
|
{% endif %}
|
|
|
|
|
|
class {{ class_name }}Model(ModelMixin, UserMixin):
|
|
"""
|
|
{{ function_name }}表
|
|
"""
|
|
__tablename__: str = '{{ table_name }}'
|
|
__table_args__: dict[str, str] = {'comment': '{{ function_name }}'}
|
|
{% if not is_sub_entity %}
|
|
{% for column in columns %}
|
|
{% if column.column_name not in ['id', 'uuid', 'tenant_id', 'created_time', 'updated_time', 'created_id', 'updated_id', 'is_deleted', 'deleted_time', 'deleted_id'] %}
|
|
{% set sqlalchemy_type = column|get_sqlalchemy_type %}
|
|
{% if not column.is_nullable %}
|
|
{{ column.column_name }}: Mapped[{{ column.python_type }}] = mapped_column({{ sqlalchemy_type }}, {% if column.is_pk %}primary_key=True, {% endif %}{% if column.is_increment %}autoincrement=True, {% endif %}nullable=False, comment='{{ column.column_comment }}')
|
|
{% else %}
|
|
{{ column.column_name }}: Mapped[{{ column.python_type }} | None] = mapped_column({{ sqlalchemy_type }}, {% if column.is_pk %}primary_key=True, {% endif %}{% if column.is_increment %}autoincrement=True, {% endif %}nullable=True, comment='{{ column.column_comment }}')
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
{% if table.sub %}
|
|
{{ sub_rel_list_name }} = relationship('{{ sub_model_class_name }}', back_populates='{{ parent_rel_name }}')
|
|
{% endif %}
|
|
{% else %}
|
|
{% for column in columns %}
|
|
{% if column.column_name not in ['id', 'uuid', 'tenant_id', 'created_time', 'updated_time', 'created_id', 'updated_id', 'is_deleted', 'deleted_time', 'deleted_id'] %}
|
|
{% set sqlalchemy_type = column|get_sqlalchemy_type %}
|
|
{% if column.column_name == sub_table_fk_name %}
|
|
{{ column.column_name }}: Mapped[{{ column.python_type }} | None] = mapped_column({{ sqlalchemy_type }}, ForeignKey('{{ parent_table_name }}.{{ parent_pk_column_name }}', ondelete='CASCADE'), {% if column.is_pk %}primary_key=True, {% endif %}{% if column.is_increment %}autoincrement=True, {% endif %}{% if (not column.is_nullable) or column.is_pk %}nullable=False{% else %}nullable=True{% endif %}, comment='{{ column.column_comment }}')
|
|
{% else %}
|
|
{% if not column.is_nullable %}
|
|
{{ column.column_name }}: Mapped[{{ column.python_type }}] = mapped_column({{ sqlalchemy_type }}, {% if column.is_pk %}primary_key=True, {% endif %}{% if column.is_increment %}autoincrement=True, {% endif %}nullable=False, comment='{{ column.column_comment }}')
|
|
{% else %}
|
|
{{ column.column_name }}: Mapped[{{ column.python_type }} | None] = mapped_column({{ sqlalchemy_type }}, {% if column.is_pk %}primary_key=True, {% endif %}{% if column.is_increment %}autoincrement=True, {% endif %}nullable=True, comment='{{ column.column_comment }}')
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
{{ parent_rel_name }} = relationship('{{ parent_model_class_name }}', back_populates='{{ parent_list_rel_name }}')
|
|
{% endif %}
|