mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-24 05:26:58 +00:00
- 删除废弃的ticket和version模块相关代码 - 将resource模块从system迁移到monitor - 移除前端资源管理相关配置 - 重构代码生成模板路径和配置 - 修复CRUD基类初始化参数问题 - 优化模板工具类路径处理 - 更新基础模型字段和配置
67 lines
2.3 KiB
Django/Jinja
67 lines
2.3 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 Base
|
|
# -*- coding:utf-8 -*-
|
|
|
|
from sqlalchemy import Column, ForeignKey, {{ importList }}
|
|
from config.database import BaseMixin, Base
|
|
{% if subTable %}
|
|
from sqlalchemy.orm import relationship
|
|
{% endif %}
|
|
|
|
class {{ tableName|snake_to_pascal_case }}Model(Base, BaseMixin):
|
|
"""
|
|
{{ functionName }}表
|
|
"""
|
|
__tablename__ = "{{ tableName }}"
|
|
|
|
{% for column in columns %}
|
|
{% if not column.columnName | is_base_column %}
|
|
{{ column.columnName }} = Column({{ column.columnType|get_sqlalchemy_type }}, {{ column | get_column_options }})
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% if subTable %}
|
|
{{ subTable.table_name }}_list = relationship('{{ subClassName }}', back_populates='{{ tableName }}')
|
|
{% endif %}
|
|
|
|
|
|
{% if subTable %}
|
|
class {{ subClassName }}(Base, BaseMixin):
|
|
"""
|
|
{{ functionName }}表
|
|
"""
|
|
__tablename__ = '{{ subTableName }}'
|
|
{% for column in subTable.columns %}
|
|
{% if not column.column_name | is_base_column %}
|
|
{{ column.column_name }} = Column({{ column.column_type | get_sqlalchemy_type }}, {% if column.column_name == subTableFkName %}ForeignKey('{{ tableName }}.id'), {% endif %}{% if column.pk %}primary_key=True, {% endif %}{% if column.increment %}autoincrement=True, {% endif %}{% if column.required %}nullable=True{% else %}nullable=False{% endif %}, comment='{{ column.column_comment }}')
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
{% if subTable %}
|
|
{{ tableName }} = relationship('{{ ClassName }}', back_populates='{{ subTable.table_name }}_list')
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
|
|
|
|
|
|
class {{ tableName|snake_to_pascal_case }}Model(Base):
|
|
"""
|
|
{{ 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})>" |