Skip to content

Instantly share code, notes, and snippets.

@rg3915
Last active February 20, 2024 07:39
Generate graphic model Django with PyGraphViz pygraphviz pydot generate model graph model 2020

How to generate graphic model Django with PyGraphViz?

sudo apt-get install -y graphviz libgraphviz-dev pkg-config
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install pygraphviz
pip uninstall pyparsing
pip install -Iv https://pypi.python.org/packages/source/p/pyparsing/pyparsing-1.5.7.tar.gz#md5=9be0fcdcc595199c646ab317c1d9a709
pip install pydot
pip install django-extensions

The next command generate the graphic of model.

python manage.py graph_models -e -g -l dot -o core.png core  # only app core
python manage.py graph_models -a -g -o models.png # all

img

References:

http://blog.birdhouse.org/2008/12/23/django-and-graphviz/

http://django-extensions.readthedocs.org/en/latest/graph_models.html#example-usage

http://stackoverflow.com/a/17902926/802542

https://coderwall.com/p/gndgjw/visualizing-your-django-models

https://code.djangoproject.com/wiki/DjangoGraphviz

https://pypi.python.org/pypi/pygraphviz/

https://pypi.python.org/pypi/pyparsing/2.0.3

@iitsmel
Copy link

iitsmel commented Dec 4, 2021

Thanks for sharing this amazing introduction. Just wanna let you know there might be a typo in graph_models.md.
python manage.py graph_models -e -g -l dot -o core.png core # olny app core
I assume you mean "only" not "olny" ?
Anyways, no biggie, thank you so much for sharing this :)

@rg3915
Copy link
Author

rg3915 commented Dec 8, 2021

Thanks @iitsmel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment