In [2]:
import fnmatch
import os
ROOT_PATH=os.path.abspath('.')
APP_NAME='myapp'
cd=ROOT_PATH
print "cd %s"%cd
for f in os.listdir(cd):
    if fnmatch.fnmatch(f, '*.sqlite3'):
        print "removing %s"%(os.path.join(ROOT_PATH,f))
        os.remove(os.path.join(cd,f))

cd=os.path.join(ROOT_PATH,APP_NAME,"migrations")
print "cd %s"%cd
for f in os.listdir(cd):
    if fnmatch.fnmatch(f, '*.pyc'):
        print "removing %s"%(os.path.join(cd,f))
        os.remove(os.path.join(cd,f))
    elif fnmatch.fnmatch(f, '0*.py'):
        print "removing %s"%(os.path.join(cd,f))
        os.remove(os.path.join(cd,f))


cd C:\Users\Wasit\Desktop\testModel\myproject
cd C:\Users\Wasit\Desktop\testModel\myproject\myapp\migrations
removing C:\Users\Wasit\Desktop\testModel\myproject\myapp\migrations\0001_initial.py
removing C:\Users\Wasit\Desktop\testModel\myproject\myapp\migrations\0001_initial.pyc
removing C:\Users\Wasit\Desktop\testModel\myproject\myapp\migrations\0002_auto_20161118_1630.py
removing C:\Users\Wasit\Desktop\testModel\myproject\myapp\migrations\__init__.pyc

In [3]:
import os
import sys
import subprocess
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"])


Migrations for 'myapp':
  myapp\migrations\0001_initial.py:
    - Create model Address
    - Create model Customer
    - Add field customer to address

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, myapp, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying myapp.0001_initial... OK
  Applying sessions.0001_initial... OK


In [4]:
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')


Out[4]:
True

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


<img src="161118_163236.png",width=60,height=60>


In [ ]: