Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate UML diagram of django app models
apt-get install python-pygraphviz
pip install django-extensions
# add 'django_extensions' to INSTALLED_APPS in settings.py
python manage.py graph_models trees -o test.png
@luisffc

This comment has been minimized.

Copy link

@luisffc luisffc commented Jan 29, 2016

On step one:
brew install graphviz # For Mac users
and then
pip install pygraphviz

@dmussaku

This comment has been minimized.

Copy link

@dmussaku dmussaku commented May 26, 2016

If you get the build error of not finding c libraries for pygraphviz, install libgraphviz-dev

@diegogslomp

This comment has been minimized.

Copy link

@diegogslomp diegogslomp commented Jul 26, 2016

If you get error installing pygraphviz on Centos:
yum install graphviz-devel

@dashdanw

This comment has been minimized.

Copy link

@dashdanw dashdanw commented Mar 28, 2017

if you're running this via windows/ubuntu integration you may need to run apt-get install pkg-config before you run pip install pygraphviz

@MaxxTak

This comment has been minimized.

Copy link

@MaxxTak MaxxTak commented Apr 30, 2017

if using bash on windows and you get this error: "CommandError: Neither pygraphviz nor pydotplus could be found to generate the image"
run: python -c 'import pygraphviz'
and if you get this error: 'ImportError: No module named pygraphviz'

run: pip install pygraphviz

and you'll be able to generate the diagram

@k4ml

This comment has been minimized.

Copy link

@k4ml k4ml commented May 10, 2017

Example diagram for Wagtail:-

python manage.py graph_models wagtailcore -o test.png

test

@leonel-lordford

This comment has been minimized.

Copy link

@leonel-lordford leonel-lordford commented Sep 18, 2017

Didn't work for me :-( Gives me django.template.exceptions.TemplateDoesNotExist: django_extensions/graph_models/digraph.dot
Just notice I'm using django-orm standalone outside a web app... just using it for accessing DB from API...
Any help for generating my models diagram?
LordFord.

@leonel-lordford

This comment has been minimized.

Copy link

@leonel-lordford leonel-lordford commented Sep 18, 2017

I'm just using django-orm-standalone and got this error: django.template.exceptions.TemplateDoesNotExist: django_extensions/graph_models/digraph.dot
I did install django-extensions etc... using pip in python3....
Maybe I need to set some ENV_VARS...
Any help?

@syabro

This comment has been minimized.

Copy link

@syabro syabro commented Dec 21, 2017

If you have this error for OS X and brew

Collecting pygraphviz
  Using cached pygraphviz-1.3.1.zip
Installing collected packages: pygraphviz
  Running setup.py install for pygraphviz ... error
    Complete output from command /Users/syabro/.virtualenvs/hoaas/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/zy/9d1g10s11d744d62zvxb67d40000gn/T/pip-build-nej0gni5/pygraphviz/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/zy/9d1g10s11d744d62zvxb67d40000gn/T/pip-u8xfe9h1-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/syabro/.virtualenvs/hoaas/include/site/python3.6/pygraphviz:
    running install
    Trying pkg-config
    Failed to find pkg-config
    Trying dotneato-config
    Failed to find dotneato-config
    Failed to find dotneato-config

    Your Graphviz installation could not be found.

            1) You don't have Graphviz installed:
               Install Graphviz (http://graphviz.org)

            2) Your Graphviz package might incomplete.
               Install the binary development subpackage (e.g. libgraphviz-dev or similar.)

            3) You are using Windows
               There are no PyGraphviz binary packages for Windows but you might be
               able to build it from this source.  See
               http://networkx.lanl.gov/pygraphviz/reference/faq.html

            If you think your installation is correct you will need to manually
            change the include_dirs and library_dirs variables in setup.py to
            point to the correct locations of your graphviz installation.

            The current setting of library_dirs and include_dirs is:
    library_dirs=None
    include_dirs=None

    error: Error locating graphviz.

try

pip install --install-option="--include-path=/usr/local/include/" --install-option="--library-path=/usr/local/lib/" pygraphviz
@ivancarrancho

This comment has been minimized.

Copy link

@ivancarrancho ivancarrancho commented Feb 21, 2018

with python 3 :(
1__ivan_ivans-imac____documents_projects_mintic-appsco__zsh_

@bmjr

This comment has been minimized.

Copy link

@bmjr bmjr commented Mar 27, 2018

For anyone with @leonel-lordford problem of Template-Does-Not-Exist ensure that you enable App_Dirs under the template settings in your chosen settings file. That worked for me!

@browniebroke

This comment has been minimized.

Copy link

@browniebroke browniebroke commented Apr 4, 2018

For people who have issues installing graphviz libraries (for some reason)

If you remove the -o option it'll print as a dot file to the stdout, which you can redirect to a file. From there, you have online converters to generate an image. This one has an interactive codepen-like editor: https://dreampuf.github.io/GraphvizOnline/

@jneuendorf

This comment has been minimized.

Copy link

@jneuendorf jneuendorf commented Jun 29, 2018

Thanks, @syabro your command worked for me (on macOS 10.13.5)! :)

@caot

This comment has been minimized.

Copy link

@caot caot commented Nov 12, 2018

Is there a way to generate a graph of a selected set of models and the related only?

@mcardozo

This comment has been minimized.

Copy link

@mcardozo mcardozo commented Jan 3, 2019

For anyone with @leonel-lordford problem of Template-Does-Not-Exist ensure that you enable App_Dirs under the template settings in your chosen settings file. That worked for me!

and for me! thank you!

@wesvetter

This comment has been minimized.

Copy link

@wesvetter wesvetter commented Mar 27, 2019

@browniebroke thanks for this tip! I couldn't get graphviz working but the dot output worked so I was able to get a graph via your link.

@moojen

This comment has been minimized.

Copy link

@moojen moojen commented May 20, 2020

Thanks, @syabro your command worked for me (on macOS 10.13.5)! :)

@syabro Same here, worked after using brew (on macOS 10.15.4). Cheers!!

@jhonvidal

This comment has been minimized.

Copy link

@jhonvidal jhonvidal commented Jun 10, 2020

Get it working, thanks.

I have a question, the graph only shows me the attributes of all kinds.

How can I get it to also show the methods of all classes?

@jhonvidal

This comment has been minimized.

Copy link

@jhonvidal jhonvidal commented Jun 10, 2020

Thanks, @syabro your command worked for me (on macOS 10.13.5)! :)

@syabro Same here, worked after using brew (on macOS 10.15.4). Cheers!!

Do you know how to also show the methods of a class?

@AgustinPardo

This comment has been minimized.

Copy link

@AgustinPardo AgustinPardo commented Mar 31, 2021

How to only show one app diagram?

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