Inspired by [http://www.hackdiary.com/archives/000093.html this nice hack by Matt Biddulph] I set up to create a similar thing for Django models. Below is an initial implementation, and here are some results generated with the OS X version of Graphviz: * [http://cavedoni.com/2006/08/camera.dot generated dot file]: resulting image in [http://cavedoni.com/2006/08/camera.pdf PDF] * [http://cavedoni.com/2006/08/mincer.dot generated dot file]: resulting image in [http://cavedoni.com/2006/08/mincer.pdf PDF] I hope people might find it useful. {{{ #!python """Django model to DOT (Graphviz) converter by Antonio Cavedoni Make sure your DJANGO_SETTINGS_MODULE is set to your project and call the script like this: $ python modelviz.py . > .dot Example: $ python modelviz.py camera.models > foo.dot """ from django.db.models.base import ModelBase from django.db.models.fields.related import \ ForeignKey, OneToOneField, ManyToManyField def generate_dot(model_module): print "digraph model {" for obj in dir(model_module): o = getattr(model_module, obj) if isinstance(o, ModelBase): for field in o._meta.fields: if type(field) in [ForeignKey, OneToOneField, ManyToManyField]: print ' %s -> %s_%s [label="%s"];' % \ (o.__name__, o.__name__, field.name, type(field).__name__) print " %s_%s -> %s" % \ (o.__name__, field.name, field.rel.to.__name__) else: print " %s -> %s_%s;" % (o.__name__, o.__name__, field.name) print "}" if __name__ == "__main__": import sys _models = __import__(sys.argv[1]) generate_dot(_models.models) }}}