To generate an image of django's models we will use the command:
python manage.py graph_models -a -g -o imagefile_name.png
# iamgefile_name.png will be the image generated
# https://django-extensions.readthedocs.io/en/latest/graph_models.html
In order to use the command graph_models we need to instal one of these library:
pygraphviz
pydot
I used Ubuntu to install the library and here there are the steps i followed:
For other operating system follow the official guide: pygraphviz.github.io/documentation/stable/i..
- sudo apt-get install graphviz graphviz-dev
- pip install pygraphviz
- pip install django-extensions
- add django_extensions to installed apps in settings.py
- python manage.py graph_models -a -g -o imagefile_name.png
If you use Docker here the steps:
- in your dockerfile use the following commands
RUN yes | apt-get install graphviz
RUN yes | apt-get install graphviz-dev
- in the requirements.txt file insert
django-extensions
pygraphviz
add django_extensions to installed apps in settings.py
docker-compose exec web python manage.py graph_models -a -g -o imagefile_name.png (web is one of my service in the docker-compose file)