see test_query.ipynb


In [4]:
import os
import sys
import subprocess
ROOT_PATH=os.getcwd()
manage = os.path.join(ROOT_PATH , "manage.py")
print(subprocess.check_output([sys.executable, manage, "makemigrations","--noinput"]))
print(subprocess.check_output([sys.executable, manage, "migrate","--noinput"]))


b'No changes detected\n'
b'Operations to perform:\n  Apply all migrations: admin, auth, contenttypes, sessions\nRunning migrations:\n  No migrations to apply.\n'

In [17]:
import pydot
import time
timestr = time.strftime("%y%m%d_%H%M%S")

dotstr=subprocess.check_output([sys.executable, manage, "graph_models", "-a"])
# with  open("models.dot","w") as f:
#     f.write(dotstr)
(graph,) = pydot.graph_from_dot_file('models.dot')
graph = pydot.graph_from_dot_data(dotstr)
graph.write_png(timestr + '.png')
#open the png


---------------------------------------------------------------------------
ParseException                            Traceback (most recent call last)
~/env/vision/lib/python3.6/site-packages/dot_parser.py in parse_dot_data(s)
    547         graphparser.parseWithTabs()
--> 548         tokens = graphparser.parseString(s)
    549         return list(tokens)

~/env/vision/lib/python3.6/site-packages/pyparsing.py in parseString(self, instring, parseAll)
   1675                 # catch and re-raise exception from here, clears out pyparsing internal stack trace
-> 1676                 raise exc
   1677         else:

~/env/vision/lib/python3.6/site-packages/pyparsing.py in parseString(self, instring, parseAll)
   1665         try:
-> 1666             loc, tokens = self._parse( instring, 0 )
   1667             if parseAll:

~/env/vision/lib/python3.6/site-packages/pyparsing.py in _parseNoCache(self, instring, loc, doActions, callPreParse)
   1411                 try:
-> 1412                     loc,tokens = self.parseImpl( instring, preloc, doActions )
   1413                 except IndexError:

~/env/vision/lib/python3.6/site-packages/pyparsing.py in parseImpl(self, instring, loc, doActions)
   4022             try_not_ender(instring, loc)
-> 4023         loc, tokens = self_expr_parse( instring, loc, doActions, callPreParse=False )
   4024         try:

~/env/vision/lib/python3.6/site-packages/pyparsing.py in _parseNoCache(self, instring, loc, doActions, callPreParse)
   1411                 try:
-> 1412                     loc,tokens = self.parseImpl( instring, preloc, doActions )
   1413                 except IndexError:

~/env/vision/lib/python3.6/site-packages/pyparsing.py in parseImpl(self, instring, loc, doActions)
   3482             else:
-> 3483                 loc, exprtokens = e._parse( instring, loc, doActions )
   3484             if exprtokens or exprtokens.haskeys():

~/env/vision/lib/python3.6/site-packages/pyparsing.py in _parseNoCache(self, instring, loc, doActions, callPreParse)
   1411                 try:
-> 1412                     loc,tokens = self.parseImpl( instring, preloc, doActions )
   1413                 except IndexError:

~/env/vision/lib/python3.6/site-packages/pyparsing.py in parseImpl(self, instring, loc, doActions)
   3804         if self.expr is not None:
-> 3805             return self.expr._parse( instring, loc, doActions, callPreParse=False )
   3806         else:

~/env/vision/lib/python3.6/site-packages/pyparsing.py in _parseNoCache(self, instring, loc, doActions, callPreParse)
   1411                 try:
-> 1412                     loc,tokens = self.parseImpl( instring, preloc, doActions )
   1413                 except IndexError:

~/env/vision/lib/python3.6/site-packages/pyparsing.py in parseImpl(self, instring, loc, doActions)
   3632                 maxException.msg = self.errmsg
-> 3633                 raise maxException
   3634             else:

~/env/vision/lib/python3.6/site-packages/pyparsing.py in parseImpl(self, instring, loc, doActions)
   3617             try:
-> 3618                 ret = e._parse( instring, loc, doActions )
   3619                 return ret

~/env/vision/lib/python3.6/site-packages/pyparsing.py in _parseNoCache(self, instring, loc, doActions, callPreParse)
   1411                 try:
-> 1412                     loc,tokens = self.parseImpl( instring, preloc, doActions )
   1413                 except IndexError:

~/env/vision/lib/python3.6/site-packages/pyparsing.py in parseImpl(self, instring, loc, doActions)
   2546             return loc+self.matchLen, self.returnString
-> 2547         raise ParseException(instring, loc, self.errmsg, self)
   2548 

ParseException: Expected {'graph' | 'digraph'} (at char 0), (line:1, col:1)

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-17-f6fcb0bb26fd> in <module>
      6 # with  open("models.dot","w") as f:
      7 #     f.write(dotstr)
----> 8 (graph,) = pydot.graph_from_dot_file('models.dot')
      9 graph = pydot.graph_from_dot_data(dotstr)
     10 graph.write_png(timestr + '.png')

~/env/vision/lib/python3.6/site-packages/pydot.py in graph_from_dot_file(path, encoding)
    236     if not PY3:
    237         s = unicode(s)
--> 238     graphs = graph_from_dot_data(s)
    239     return graphs
    240 

~/env/vision/lib/python3.6/site-packages/pydot.py in graph_from_dot_data(s)
    219     @rtype: `list` of `pydot.Dot`
    220     """
--> 221     return dot_parser.parse_dot_data(s)
    222 
    223 

~/env/vision/lib/python3.6/site-packages/dot_parser.py in parse_dot_data(s)
    552             err.line +
    553             " "*(err.column-1) + "^" +
--> 554             err)
    555         return None

TypeError: must be str, not ParseException

In [16]:
from IPython.display import display, Markdown, Latex
md='''<img src="%s",width=60,height=60>'''%(timestr + '.png')
display(Markdown(md))


<img src="181105_224841.png",width=60,height=60>


In [ ]:


In [ ]: