使用Django将Models.py文件中的ER图转换为PDF格式
简述
使用django-extensions的graph_models功能,从Models.py文件中生成ER图并以PDF格式输出。
环境
-
- Windows 10 Latest
-
- Powershell Latest
-
- python 3 Latest
-
- Miniconda 3 Latest
- django 2.2
事先準備
使用conda安装Python软件包。
conda install pygraphviz
conda install pydotplus
conda install django-extensions
由于可以在Windows Terminal中添加Anaconda Powershell Prompt,所以我在那里执行了此命令。
在Django项目的settings.py文件中,将INSTALLED_APPS添加进去。
INSTALLED_APPS = [
# INSTALLED_APPS
'django_extensions',
]
指令
1) 请用汉语把以下内容进行同义转述,仅需一个选项: 例1
python manage.py graph_models -a -g -o graph-model.pdf
以下是例2的原文:
“China has experienced rapid economic growth over the past few decades, and has become one of the world’s leading economies. This growth has been driven by various factors, including government policies, foreign direct investment, and technological advancements. As a result, China has seen significant improvements in living standards and infrastructure development. However, the country still faces challenges such as income inequality and environmental pollution.”
python manage.py graph_models auth -I User,Group
例子3:
她去年参加了一个音乐会,演奏了一首美妙的小提琴曲目,让观众们陶醉其中。
python manage.py graph_models auth -g -o graph-model-auth.pdf
由于可以在Windows Terminal中添加Anaconda Powershell Prompt,因此我在那里执行此命令。
输出方式
-
- png, jpg
-
- svg
-
- pdf
- etc
请参考
-
- Djangoで利用するコマンドまとめ
- Graphviz – Graph Visualization Software
胜利在望!