优化更新

This commit is contained in:
2026-09-13 18:12:07 +08:00
parent 7f758cc6e9
commit d7a081e8b7
92 changed files with 2429 additions and 1117 deletions
@@ -63,7 +63,7 @@ Web API 批量生成最多支持 50 个表。CLI 无限制,但建议逐表生
**解决**:确保在项目根目录(包含 `manage.py` 和 `generator.py` 的目录)执行:
```bash
cd /data/apps/DjangoAdmin_Django_EleVue
cd /data/apps/DjangoAdmin_Django_NaiveVue
python generator.py django_example
```
@@ -106,7 +106,7 @@ Jinja2 模板文件,分为后端模板(7 个)和前端模板(ui/ 6 个 +
## 使用限制
:::warning 使用前提
1. **数据库要求**:代码生成器基于 MySQL 的 `information_schema` 查询表结构,仅支持 MySQL 数据库。
1. **数据库要求**:代码生成器基于 MySQL 的 `information_schema` 查询表结构,仅支持 MySQL 数据库。其他数据库(PostgreSQL、Oracle、SQL Server 等)需手动创建模块。
2. **表结构要求**:不支持复合主键、外键关联等复杂表结构,建议使用单主键(自增 id)的标准业务表。
3. **环境要求**:需确保 Django 环境已初始化、MySQL 和 Redis 服务正常运行。
:::
@@ -162,7 +162,7 @@ public/templates/
修改 `public/templates/models.py.tpl`:
```jinja2
```jinja
{% if f.type == 'CharField' %}
{{ f.name }} = models.CharField(
max_length={{ f.max_length or 255 }},
@@ -177,7 +177,7 @@ public/templates/
修改 `public/templates/services.py.tpl`,在添加方法中添加自定义校验:
```jinja2
```jinja
def add_{{ app_name }}(request):
# ... 原有代码 ...
# 自定义校验:检查名称是否重复
@@ -190,7 +190,7 @@ def add_{{ app_name }}(request):
修改 `public/templates/ui/columns.ts.tpl`:
```jinja2
```jinja
{% for f in list_fields %}
{
label: '{{ f.label }}',
@@ -208,7 +208,7 @@ def add_{{ app_name }}(request):
在 `public/templates/` 下新建 `test.py.tpl`:
```jinja2
```jinja
# tests/test_{{ app_name }}.py
from django.test import TestCase
from application.{{ app_name }}.models import {{ model_class_name }}
@@ -247,7 +247,7 @@ backend_templates = [
## Jinja2 语法速查
```jinja2
```jinja
{# 注释 #}
{# 变量输出 #}