mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-24 13:37:13 +00:00
移除不必要的配置字段如作者、模板类型等,优化字段初始化逻辑 重构模板生成逻辑,移除主子表和树表模板支持 优化前端代码生成页面,简化配置步骤和表单验证 更新文档中的代码生成模块说明和快速开始指南
28 lines
1.1 KiB
Django/Jinja
28 lines
1.1 KiB
Django/Jinja
# -*- coding: utf-8 -*-
|
|
|
|
from typing import Optional
|
|
from sqlalchemy import String, Integer, Text, DateTime, Boolean, ForeignKey
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.core.base_model import CreatorMixin
|
|
|
|
|
|
class {{ class_name }}Model(CreatorMixin):
|
|
"""
|
|
{{ function_name }}表
|
|
"""
|
|
|
|
__tablename__ = '{{ table_name }}'
|
|
__table_args__ = {'comment': '{{ function_name }}'}
|
|
__loader_options__ = ["creator"]
|
|
|
|
{% for column in columns %}
|
|
{% if column.column_name not in ['id', 'creator_id', 'description', 'created_at', 'updated_at'] %}
|
|
{{ column.column_name }}: Mapped[Optional[{{ column.python_type }}]] = mapped_column({{ column.column_type|get_sqlalchemy_type }}, {% if column.pk %}primary_key=True, {% endif %}{% if column.increment %}autoincrement=True, {% endif %}{% if column.required or column.pk %}nullable=False{% else %}nullable=True{% endif %}, comment='{{ column.column_comment }}')
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
{% if table.sub %}
|
|
{{ sub_class_name }}_list = relationship('{{ sub_class_name }}', back_populates='{{ business_name }}')
|
|
{% endif %}
|