blob: 0075f591e76ac27551978948dbd89e0810a08b16 [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 = []
Sapan Bhatia3bbf5ed2014-01-13 13:29:12 -050023
Siobhan Tullycf04fb62014-01-11 11:25:57 -050024for c in g.values():
Sapan Bhatiad7425452013-09-03 11:45:15 -040025 if type(c)==type(PlCoreBase):
26 model_classes.append(c)
27 class_names.append(c.__name__)
28
29
30if (output=='-dot'):
31 print "digraph plstack {";
32 for c in model_classes:
33 fields = c._meta.fields
34 for f in fields:
Siobhan Tullycf04fb62014-01-11 11:25:57 -050035 if type(f)==ForeignKey and f.name.title() in class_names:
36 print '\t"%s"->"%s";'%(c.__name__,f.name.title())
Sapan Bhatiad7425452013-09-03 11:45:15 -040037 print "}\n";
38elif (output=='-json'):
39 d = {}
40 for c in model_classes:
41 fields = c._meta.fields
42 for f in fields:
Siobhan Tullycf04fb62014-01-11 11:25:57 -050043 if type(f)==ForeignKey and f.name.title() in class_names:
Sapan Bhatiad7425452013-09-03 11:45:15 -040044 try:
Siobhan Tullycf04fb62014-01-11 11:25:57 -050045 d[c.__name__].append(f.name.title())
Sapan Bhatiad7425452013-09-03 11:45:15 -040046 except KeyError:
Siobhan Tullycf04fb62014-01-11 11:25:57 -050047 d[c.__name__]=[f.name.title()]
Sapan Bhatiad7425452013-09-03 11:45:15 -040048 print json.dumps(d,indent=4)