1 2 3 4 5 6 7 8 9 10 11 12 13 | 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__))
except ImportError:
print "INFO: could not find a django env"
...
def main():
...
load_django_models()
|
More like this
- Autoload Django Models When Using ./manage.py shell by sheats 4 years, 4 months ago
- Use django-admin.py instead of manage.py by whiteinge 3 years, 11 months ago
- cron/console bootstrap django by nstrite 4 years, 9 months ago
- PyCrust Shell by robvdl 4 years, 7 months ago
- Facebook shell by stephenemslie 2 years, 8 months ago
Comments
great snippet, I use ipython for other things (virtually everything actually) so I changed the code to
but other than that, terrific
#
If you're using a virtualenv and ipython is having trouble finding your project settings, I found that adding this to the snippet helped:
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
#