Files
RuoYi-Vue3-FastAPI/ruoyi-fastapi-backend/module_generator/templates/python/do.py.jinja2
2025-02-14 17:42:36 +08:00

41 lines
1.5 KiB
Django/Jinja

from datetime import datetime
from sqlalchemy import Column, DateTime, Integer, String
{% if table.sub %}
from sqlalchemy.orm import relationship
{% endif %}
from config.database import Base
class {{ ClassName }}(Base):
"""
{{ functionName }}
"""
__tablename__ = '{{ tableName }}'
{% for column in columns %}
{{ column.column_name }} = Column({{ column.column_type | get_sqlalchemy_type }}, {% 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 }}')
{% endfor %}
{% if table.sub %}
{{ table.sub_table.business_name }} = relationship('{{ table.sub_table.class_name }}', back_populates='{{ businessName }}')
{% endif %}
{% if table.sub %}
class {{ table.sub_table.class_name }}(Base):
"""
{{ table.sub_table.function_name }}
"""
__tablename__ = '{{ table.sub_table.table_name }}'
{% for column in table.sub_table.columns %}
{{ column.column_name }} = Column({{ column.column_type | get_sqlalchemy_type }}, {% 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 }}')
{% endfor %}
{% if table.sub %}
{{ businessName }} = relationship('{{ ClassName }}', back_populates='{{ table.sub_table.business_name }}')
{% endif %}
{% endif %}