blob: 2d95e9d073f51d09794a26df3e2c1827a9ee54ac [file] [log] [blame]
Sapan Bhatia26d40bc2014-05-12 15:28:02 -04001#!/usr/bin/python
2
3import os
4import pdb
5import sys
6import json
7
8sys.path.append('.')
9
10os.environ.setdefault("DJANGO_SETTINGS_MODULE", "planetstack.settings")
11
12from django.db.models.fields.related import ForeignKey
13from core.models import *
14
15try:
16 output = sys.args[1]
17except:
18 output = '-json'
19
20g = globals()
21model_classes = []
22class_names = []
23for c in g.values():
24 if type(c)==type(PlCoreBase):
25 model_classes.append(c)
26 class_names.append(c.__name__)
27
28
29if (output=='-dot'):
30 print "digraph plstack {";
31 for c in model_classes:
32 fields = c._meta.fields
33 for f in fields:
34 if type(f)==ForeignKey and f.name.title() in class_names:
35 print '\t"%s"->"%s";'%(c.__name__,f.name.title())
36 print "}\n";
37elif (output=='-json'):
38 d = {}
39 for c in model_classes:
40 fields = c._meta.fields
41 for f in fields:
42 if type(f)==ForeignKey and f.name.title() in class_names:
43 try:
44 d[c.__name__].append(f.name.title())
45 except KeyError:
46 d[c.__name__]=[f.name.title()]
47 print json.dumps(d,indent=4)
48
49