Skip to content

Commit

Permalink
Call django.setup() if the app registry isn't initialized yet
Browse files Browse the repository at this point in the history
This is needed for the iPython notebook extension when running Django
1.7.
  • Loading branch information
dekkers committed Jun 25, 2014
1 parent 4ee7d58 commit 57d33a4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions django_extensions/management/shells.py
Expand Up @@ -79,6 +79,21 @@ def import_items(import_directives, style, quiet_load=False):


def import_objects(options, style):
# Django 1.7 introduced the app registry which must be initialized before we
# can call get_apps(). Django already does this for us when we are invoked
# as manage.py command, but we have to do it ourselves if when running as
# iPython notebook extension, so we call django.setup() if the app registry
# isn't initialized yet. The try/except can be removed when support for
# Django 1.6 is dropped.
try:
from django.apps import apps
from django import setup
except ImportError:
pass
else:
if not apps.ready:
setup()

from django.db.models.loading import get_models, get_apps
mongoengine = False
try:
Expand Down

0 comments on commit 57d33a4

Please sign in to comment.