feat: 添加代码生成功能
This commit is contained in:
44
templates/python/model.py.jinja
Normal file
44
templates/python/model.py.jinja
Normal file
@@ -0,0 +1,44 @@
|
||||
# _*_ coding : UTF-8 _*_
|
||||
# @Time : {{ current_time }}
|
||||
# @UpdateTime : {{ current_time }}
|
||||
# @Author : {{ author }}
|
||||
# @File : {{ table_name }}.py
|
||||
# @Comment : 本程序用于{{ table_comment }}模型
|
||||
|
||||
from tortoise import fields
|
||||
|
||||
from models.common import BaseModel
|
||||
|
||||
|
||||
class {{ class_name }}(BaseModel):
|
||||
"""
|
||||
{{ table_comment }}模型
|
||||
"""
|
||||
{% for column in columns %}
|
||||
{%- set params = [] %}
|
||||
{%- if column.max_length is not none %}{% set params = params + ["max_length=" ~ column.max_length] %}{% endif %}
|
||||
{%- if column.is_nullable %}{% set params = params + ["null=True"] %}{% endif %}
|
||||
{%- if column.is_unique %}{% set params = params + ["unique=True"] %}{% endif %}
|
||||
{%- if column.default is not none %}{% set params = params + ["default=" ~ column.default] %}{% endif %}
|
||||
{%- if column.column_comment %}{% set params = params + ['description="' ~ column.column_comment ~ '"'] %}{% endif %}
|
||||
{%- if column.column_name %}{% set params = params + ['source_field="' ~ column.column_name ~ '"'] %}{% endif %}
|
||||
|
||||
{{ column.python_name }} = fields.{{ column.field_type }}({{ params | join(", ") }})
|
||||
"""
|
||||
{{ column.column_comment }}。
|
||||
{%- if column.max_length is not none %}
|
||||
- 最大长度为 {{ column.max_length }} 个字符
|
||||
{%- endif %}
|
||||
- 映射到数据库字段 {{ column.column_name }}
|
||||
{%- if column.is_nullable %}
|
||||
- 可为空
|
||||
{%- endif %}
|
||||
{%- if column.default is not none %}
|
||||
- 默认值:{{ column.default }}
|
||||
{%- endif %}
|
||||
"""
|
||||
{% endfor %}
|
||||
|
||||
class Meta:
|
||||
table = "{{ table_name }}"
|
||||
table_description = "{{ table_comment }}"
|
||||
Reference in New Issue
Block a user