blob: de07a78182f5d4c07fa3226775e67158fb4dcff5 [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
Scott Baker2125dab2015-02-18 11:29:05 -080010os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
Sapan Bhatia26d40bc2014-05-12 15:28:02 -040011
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