blob: 2d95e9d073f51d09794a26df3e2c1827a9ee54ac [file] [log] [blame]
Sapan Bhatiad7425452013-09-03 11:45:15 -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
Siobhan Tullycf04fb62014-01-11 11:25:57 -050013from core.models import *
Sapan Bhatiad7425452013-09-03 11:45:15 -040014
Siobhan Tullycf04fb62014-01-11 11:25:57 -050015try:
16 output = sys.args[1]
17except:
18 output = '-json'
Sapan Bhatiad7425452013-09-03 11:45:15 -040019
Siobhan Tullycf04fb62014-01-11 11:25:57 -050020g = globals()
Sapan Bhatiad7425452013-09-03 11:45:15 -040021model_classes = []
22class_names = []
Siobhan Tullycf04fb62014-01-11 11:25:57 -050023for c in g.values():
Sapan Bhatiad7425452013-09-03 11:45:15 -040024 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:
Siobhan Tullycf04fb62014-01-11 11:25:57 -050034 if type(f)==ForeignKey and f.name.title() in class_names:
35 print '\t"%s"->"%s";'%(c.__name__,f.name.title())
Sapan Bhatiad7425452013-09-03 11:45:15 -040036 print "}\n";
37elif (output=='-json'):
38 d = {}
39 for c in model_classes:
40 fields = c._meta.fields
41 for f in fields:
Siobhan Tullycf04fb62014-01-11 11:25:57 -050042 if type(f)==ForeignKey and f.name.title() in class_names:
Sapan Bhatiad7425452013-09-03 11:45:15 -040043 try:
Siobhan Tullycf04fb62014-01-11 11:25:57 -050044 d[c.__name__].append(f.name.title())
Sapan Bhatiad7425452013-09-03 11:45:15 -040045 except KeyError:
Siobhan Tullycf04fb62014-01-11 11:25:57 -050046 d[c.__name__]=[f.name.title()]
Sapan Bhatiad7425452013-09-03 11:45:15 -040047 print json.dumps(d,indent=4)
48
49