feat(docs): enhance README and backend documentation for new user onboarding and backend conventions

- Added a "Start Here" section in both English and Chinese README files to guide new users on running the project locally and exploring its features.
- Introduced backend conventions for date and serialization handling, clarifying the use of Pydantic v2 and PostgreSQL.
- Updated the "Quick Start" section with detailed steps for first-time local setup, including environment requirements and backend setup instructions.
- Improved overall structure and clarity of documentation to facilitate better understanding for developers and contributors.
This commit is contained in:
zhangtao
2026-03-29 07:25:09 +08:00
parent bf26563083
commit d2a863652e
88 changed files with 4846 additions and 2558 deletions
@@ -3,9 +3,6 @@
{% for model_import in model_import_list %}
{{ model_import }}
{% endfor %}
{% if table.sub %}
from sqlalchemy.orm import relationship
{% endif %}
from sqlalchemy.orm import Mapped, mapped_column
from app.core.base_model import ModelMixin, UserMixin
@@ -19,13 +16,28 @@ class {{ class_name }}Model(ModelMixin, UserMixin):
__table_args__: dict[str, str] = {'comment': '{{ function_name }}'}
__loader_options__: list[str] = ["created_by", "updated_by"]
{% if not is_sub_entity %}
{% for column in columns %}
{% if column.column_name not in ['id', 'uuid', 'status', 'description', 'created_time', 'updated_time', 'created_id', 'updated_id'] %}
{% set sqlalchemy_type = column|get_sqlalchemy_type %}
{{ column.column_name }}: Mapped[{{ column.python_type }} | None] = mapped_column({{ 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 }}')
{{ 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 %}{% if (not column.is_nullable) or column.is_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 }}')
{{ 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', 'status', 'description', 'created_time', 'updated_time', 'created_id', 'updated_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(ForeignKey('{{ parent_table_name }}.{{ parent_pk_column_name }}', ondelete='CASCADE'), {{ sqlalchemy_type }}, {% 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 %}
{{ 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 %}{% if (not column.is_nullable) or column.is_pk %}nullable=False{% else %}nullable=True{% endif %}, comment='{{ column.column_comment }}')
{% endif %}
{% endif %}
{% endfor %}
{{ parent_rel_name }} = relationship('{{ parent_model_class_name }}', back_populates='{{ parent_list_rel_name }}')
{% endif %}
@@ -8,9 +8,7 @@ from fastapi import Query
{% for import_stmt in schema_import_list %}
{{ import_stmt }}
{% endfor %}
{% if table.created_time %}
from app.core.validator import DateTimeStr
{% endif %}
{# DateTimeStr 由 schema_import_list 在存在 created_time/updated_time 列时注入 #}
from app.common.enums import QueueEnum
from app.core.base_schema import BaseSchema, UserBySchema
@@ -60,10 +58,10 @@ class {{ class_name }}QueryParam:
{{ column.column_name }}: {{ column.python_type }} | None = Query(None, description="{{ column.column_comment }}"),
{% endif %}
{% endfor %}
{% if table.created_time %}
{% if 'created_time' in table_column_names %}
created_time: list[DateTimeStr] | None = Query(None, description="创建时间范围", examples=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
{% endif %}
{% if table.updated_time %}
{% if 'updated_time' in table_column_names %}
updated_time: list[DateTimeStr] | None = Query(None, description="更新时间范围", examples=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
{% endif %}
) -> None:
@@ -77,21 +75,13 @@ class {{ class_name }}QueryParam:
self.{{ column.column_name }} = (QueueEnum.eq.value, {{ column.column_name }})
{% endif %}
{% endfor %}
{% if table.created_time %}
{% if 'created_time' in table_column_names %}
# 时间范围查询
if created_time and len(created_time) == 2:
self.created_time = (QueueEnum.between.value, (created_time[0], created_time[1]))
{% endif %}
{% if table.updated_time %}
{% if 'updated_time' in table_column_names %}
if updated_time and len(updated_time) == 2:
self.updated_time = (QueueEnum.between.value, (updated_time[0], updated_time[1]))
{% endif %}
{% if table.created_id %}
# 关联查询字段
if created_id:
self.created_id = (QueueEnum.eq.value, created_id)
{% endif %}
{% if table.updated_id %}
if updated_id:
self.updated_id = (QueueEnum.eq.value, updated_id)
{% endif %}
{# created_id / updated_id 若为 EQ 查询列,已在上方 query_type 循环中处理 #}