django 中生成 model 的关系图
版权声明:本文系作者原创。未经许可,不得转载。
django提供第三方插件django-extensions,可以用来将django中的model生成直观的图。用法如下:
一、安装包
$sudo apt-get install graphviz
$pip install django-extensions
二、配置
在django的setting.py文件中,找到INSTALLED_APPS,并添加 django_extensions。举例如下:
INSTALLED_APPS = (
...
'django_extensions',
)
三、生成dot文件和png图片
# Create a dot file
$ ./manage.py graph_models -a > my_project.dot
注:也可以对单独某个app生成dot文件。
# Create a dot file for only the 'foo' and 'bar' applications of your project
$ ./manage.py graph_models foo bar > my_project.dot
生成图片,支持两种格式
$ dot -Tps my_project.dot > my_project.eps
$ dot -Tpng my_project.dot > my_project.png
辛巴
it男
256 声望
4 粉丝
推荐阅读
mac下编译go-ethereum
macos: 10.14.4 下载go-ethereum源码,按照文档执行命令编译: $ make all 报错:fatal error: 'stdlib.h' file not found /usr/include 查看xcode是否安装: $ xcode-select --install xcode-select: error: com...
lansheng228赞 2阅读 3.2k
Django笔记十三之select_for_update等选择和更新等相关操作
本篇笔记将介绍 update 和 create 的一些其他用法,目录如下:get_or_createupdate_or_createselect_for_updatebulk_createbulk_update1、get_or_create前面我们介绍过 get() 和 create() 的用法,那么 get_or_cr...
Hunter阅读 773
Django笔记十二之defer、only指定返回字段
defer 的英语单词的意思是 延迟、推迟,我们可以通过将字段作为参数传入,可以达到在获取数据的时候指定不获取该字段数据,常用于一些 textfield 字段上。
Hunter阅读 730
Django笔记十四之统计总数、最新纪录和空值判断等功能
本篇笔记将介绍一些 Django 查询中统计总数、最新纪录和空值判断等功能。countin_bulklatest、earliestfirst、lastexistscontains、icontainsgt、gte、lt、ltestartswith、istartswithisnull1、count返回查询的 Q...
Hunter阅读 689
Django笔记六之外键ForeignKey介绍
这一篇笔记介绍 Django 系统 model 的外键处理,ForeignKey 以及相应的处理方法。这是一种一对多的字段类型,表示两张表之间的关联关系。本篇笔记的目录如下:on_deleterelated_namerelated_query_name外键字段的...
Hunter阅读 672
Django大坑之外键设置外键冲突
用Django开发了一个在线教育网站,众所周知,Django是一个开发后端的一个强大框架,用了它就不用管MySQL里面的增删改查,直接在PyCharm里迁移搞定。想在课程机构页显示课程信息表里的数据,就不得不用到外键。
achievability阅读 631
Django笔记八之model中Meta参数的使用
前面介绍了 model 的字段属性,字段类型,这篇笔记介绍一下 model 的 Meta 选项。这个选项提供了一些参数,比如排序(ordering),表名(db_table)等。但这都不是必需的,都是作为可选项,主要是为使用者提供方...
Hunter阅读 605
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。