dynamic model graph

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
urls.py ----------

from django.conf.urls.defaults import *

urlpatterns = patterns('',
  (r'^model_graph/$','<my_project>.<my_app>.views.model_graph'),
)


<my_app>/views.py ----------

from django.http import HttpResponse
from subprocess import Popen,PIPE
from <my_project>.utils.modelviz import generate_dot

def model_graph(request):
  options = dict((str(key),val) for key,val in request.GET.iteritems())
  if 'app_labels' in options:
    app_labels = options['app_labels']
    del options['app_labels']
  if 'image_type' in options:
    image_type = options['image_type'][0]
    del options['image_type']

  dot = Popen(['dot','-T%s' % image_type],stdin=PIPE,stdout=PIPE)
  content = generate_dot(app_labels,**options)

  if image_type == 'svg' : image_type = 'svg+xml'
  response = HttpResponse(mimetype='image/%s' % image_type)

  dot.stdin.write(content)
  dot.stdin.close()
  response.write(dot.stdout.read())
  dot.stdout.close()

  return response

More like this

  1. Automatic graph of your database structure by adamlofts 4 years, 6 months ago
  2. Download images as png or pdf by gkelly 6 years, 1 month ago
  3. Unit Test Profiling for Django 1.3/1.4 by hoffmaje 1 year ago
  4. FilterManager by sergejdergatsjev 4 years, 5 months ago
  5. Model dependency graph using graphviz (script) by andrew 4 years, 8 months ago

Comments

(Forgotten your password?)