A personal summary of how to automatically generate model relationships using graph_models in Django extensions. The procedure is to run inside the docker container, not env.
Install the required packages.
pip install pygraphviz
pip install pydotplus
pip install django-extensions
Note that if you try to install pygraphviz in a windows environment, you need to install the VC build tool.
Also, when doing it in a docker container, the following work was also required. Install graphviz.
apt-get install -y graphviz
If you want to output in Japanese, install Japanese fonts. Prepare the ttc file appropriately from windows etc. It's easy to put it in the Dockerfile.
$ cp meiryob.ttc /usr/share/fonts
$ fc-cache -fv
If you give verbose-name to the model itself or the field in advance, you can use that name in the model diagram.
python3 manage.py graph_models -g -o <output name> .png --verbose-names --disable-abstract-fields <app name>
I couldn't output jpg in my environment, but can I really do it?
Also, --verbose-names
is an option to use verbose-name, and --disable-abstract-fields
is an option to not include the inherited fields. There are many other options, such as --exclude-models
to exclude unwanted models.
PDF ER diagram of Models.py with Django
Recommended Posts