Auto generate uml diagrams with Django
So, I recently created this GREAT UML/Class diagram hybrid for a Django project of mine at Electronic Arts. Unfortunately, I lost the Omnigraffle source file for it… So, I went on a mission to find out if there are any auto generating UML tools available for Django, and I was in luck.
django-command-extensions
I found a command that was available in this “django-command-extensions” application that exports dot files, pngs, etc of your models into a UML document. Great! But it also came with a lot of other stuff, some useful, some not. Check it out here:
http://code.google.com/p/django-command-extensions/
Installation
It is worthy to note that I installed this on CentOS! I did a wget on the following source file (the link below may be out of date, check out the link above to see if there is a newer version available for download)
wget http://django-command-extensions.googlecode.com/files/django-extensions-0.4.1.tar.gz
tar –xzvf django-extensions-0.4.1.tar.gz
python setup.py install
Now this package is installed. The next step is to install this application in the “INSTALLED_APPS” section of your projects settings.py file.
INSTALLED_APPS = (
…
‘django_extensions’,
)
After you do that, do a ./manage.py help, and you should be able to see a list of all the newly available commands. The one you are looking for in particular is graph_models. More information on the model graphing can be found here:
http://code.google.com/p/django-command-extensions/wiki/GraphModels
Now, before you can actually use the command, you’ll have to install graphviz and pygraphviz.
Ubuntu:
sudo apt-get install graphviz-dev
sudo apt-get install python-pygraphviz
Red Hat:
sudo yum install graphviz-devel
wget http://pypi.python.org/packages/source/p/pygraphviz/pygraphviz-1.0.tar.gz
tar –xzvf pygraphviz-1.0.tar.gz
cd pygraphviz-1.0
python setup.py installcd pygraphviz-1.0
Once you do that, go ahead and generate your graph!
dot file:
./manage.py graph_models –a > my_project.dot
png:
./manage.py graph_models –a –g –o my_project_visualized.png
Happy UML-ing!