This broke with IPython 0.11 which completely changed the config format. IPython added a profile structure but the way Django shell calls IPython, it never seems to load a profile. To get that to work, I just modified the shell command and placed it into addons/management/commands directories as ishell.py, touched __init__.py in all of the subdirectories, and placed ishell.py in the commands directory.
Now that IPython is changed to an embed call, it inherits the environment from django and it loads the default profile from ipython. I prefer the subcommand approach because that lets everything be kept with the django setup rather than this personal ipython command.
Relevant commands (Download the original)
import IPython import datetime from django.db.models.loading import get_models for m in get_models(): exec ("from %s import %s" % (m.__module__, m.__name__)) IPython.embed()
Model Loading via ipy_user.conf.py (IPython < 0.11):
def main(): load_django_models() ip.ex("import datetime") ip.ex("zz_curtime = datetime.datetime.now()") # some config helper functions you can use def import_all(modules): """ Usage: import_all("os sys") """ for m in modules.split(): ip.ex("from %s import *" % m) def execf(fname): """ Execute a file in user namespace """ ip.ex('execfile("%s")' % os.path.expanduser(fname)) def load_django_models(): try: from django.db.models.loading import get_models for m in get_models(): ip.ex("from %s import %s" % (m.__module__, m.__name__)) print 'INFO: Loaded Django models.' except ImportError: pass
No comments:
Post a Comment