47

Is it possible to generate a diagram of an entire Django site? For example, to understand the model/database structure I use graphViz which is extremely useful for keeping track of the model structure, and very useful for discussions.

I was curious if something similar existed for the complete Django site so that urls/models/views/templates could all be represented graphically. I don't quite know what that would look like but am curious if any tool exists to do this.

This would programmatically generate a diagram showing the code flow between different parts of the site.

Cœur
  • 37,241
  • 25
  • 195
  • 267
djq
  • 14,810
  • 45
  • 122
  • 157
  • 2
    I've started working on app that solves this. Its still quite barebones at the moment, but it [produces interactive HTML graphs from django model definitions](https://github.com/LegoStormtroopr/django-spaghetti-and-meatballs), like this http://i.stack.imgur.com/lvxSG.png –  Aug 10 '15 at 00:44
  • 2
    Nice! I'm checking it out now. Unfortunately this question is closed, otherwise I'd suggest adding it as an answer. – djq Aug 10 '15 at 17:58
  • 1
    I've just released a solution for this too, with interactivity in the page: [`django-schema-graph`](https://github.com/meshy/django-schema-graph). [It looks like this](https://raw.githubusercontent.com/meshy/django-schema-graph/9b034191776edc8c9608ef4e3f5414033f79d9a0/docs-images/schema-graph.png). – meshy Feb 23 '20 at 13:16

4 Answers4

40

You can use django-extensions app for generating model visualisations.

setting.py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    '...',

    'django_extensions',
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

Give this command in terminal

python manage.py graph_models -a -o myapp_models.png

This will generate a png file named myapp_models.png. It will have visualised image of the models. More documentation can be found here.

César
  • 9,939
  • 6
  • 53
  • 74
Muhammed K K
  • 1,100
  • 2
  • 8
  • 19
  • 1
    This is useful in general, but I am interested in advice on how to chose more than just the models. – djq May 14 '13 at 11:30
  • 3
    The link above does not work anymore, use this one [graph-models](https://django-extensions.readthedocs.io/en/latest/graph_models.html) – PeterN Mar 15 '22 at 10:34
  • Not genarate .png, Error ends with: ModuleNotFoundError: No module named 'django_extensions', I have add 'django_extensions', in `INSTALLED_APPS` – parmer_110 Apr 15 '23 at 21:23
33

Here you can find a list of Python-to-UML tools. The one called GraphModels in django-extensions (PyPI) may cover what you're looking for.

Nick T
  • 25,754
  • 12
  • 83
  • 121
Jordi Cabot
  • 8,058
  • 2
  • 33
  • 39
  • As far as I know, GraphModels is only for UML of models and not for the complete app. – yeaske Nov 07 '14 at 22:56
  • Excuse me, [GraphModels](http://django-extensions.readthedocs.io/en/latest/graph_models.html) can only successfully install on Linux? (couldn't install on Windows 10) – Tony Chou Jul 16 '18 at 01:30
8

I've stumbled upon this problem today and I found django-dia. It looks good, if you like Dia!

janek37
  • 572
  • 5
  • 16
  • Error me: The term 'manage.py' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify th at the path is correct and try again. – parmer_110 Apr 15 '23 at 21:21
0

You can use django-extension for generating the app models i.e database. and also you can generate UML generating applications.

Rahul
  • 11
  • 2