django-extensions: shell_plus --notebook not working in 1.7

from docs looks like there’s a new setup() method.

---------------------------------------------------------------------------
AppRegistryNotReady                       Traceback (most recent call last)
<ipython-input-1-7474fc4fe95e> in <module>()
      [CODE ACCESSING MODELS VIA DJANGO ORM]

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\manager.pyc in manager_method(self, *args, **kwargs)
     90         def create_method(name, method):
     91             def manager_method(self, *args, **kwargs):
---> 92                 return getattr(self.get_queryset(), name)(*args, **kwargs)
     93             manager_method.__name__ = method.__name__
     94             manager_method.__doc__ = method.__doc__

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\query.pyc in filter(self, *args, **kwargs)
    687         set.
    688         """
--> 689         return self._filter_or_exclude(False, *args, **kwargs)
    690 
    691     def exclude(self, *args, **kwargs):

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\query.pyc in _filter_or_exclude(self, negate, *args, **kwargs)
    705             clone.query.add_q(~Q(*args, **kwargs))
    706         else:
--> 707             clone.query.add_q(Q(*args, **kwargs))
    708         return clone
    709 

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\sql\query.pyc in add_q(self, q_object)
   1285         existing_inner = set(
   1286             (a for a in self.alias_map if self.alias_map[a].join_type == self.INNER))
-> 1287         clause, require_inner = self._add_q(where_part, self.used_aliases)
   1288         self.where.add(clause, AND)
   1289         for hp in having_parts:

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\sql\query.pyc in _add_q(self, q_object, used_aliases, branch_negated, current_negated)
   1312                 child_clause, needed_inner = self.build_filter(
   1313                     child, can_reuse=used_aliases, branch_negated=branch_negated,
-> 1314                     current_negated=current_negated, connector=connector)
   1315                 joinpromoter.add_votes(needed_inner)
   1316             target_clause.add(child_clause, connector)

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\sql\query.pyc in build_filter(self, filter_expr, branch_negated, current_negated, can_reuse, connector)
   1136         if not arg:
   1137             raise FieldError("Cannot parse keyword query %r" % arg)
-> 1138         lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
   1139 
   1140         # Work out the lookup type and remove it from the end of 'parts',

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\sql\query.pyc in solve_lookup_type(self, lookup)
   1074             if aggregate:
   1075                 return aggregate_lookups, (), aggregate
-> 1076         _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
   1077         field_parts = lookup_splitted[0:len(lookup_splitted) - len(lookup_parts)]
   1078         if len(lookup_parts) == 0:

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\sql\query.pyc in names_to_path(self, names, opts, allow_many, fail_on_missing)
   1337                 name = opts.pk.name
   1338             try:
-> 1339                 field, model, direct, m2m = opts.get_field_by_name(name)
   1340             except FieldDoesNotExist:
   1341                 # We didn't found the current field, so move position back

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\options.pyc in get_field_by_name(self, name)
    414                 return self._name_map[name]
    415             except AttributeError:
--> 416                 cache = self.init_name_map()
    417                 return cache[name]
    418         except KeyError:

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\options.pyc in init_name_map(self)
    443         # We intentionally handle related m2m objects first so that symmetrical
    444         # m2m accessor names can be overridden, if necessary.
--> 445         for f, model in self.get_all_related_m2m_objects_with_model():
    446             cache[f.field.related_query_name()] = (f, model, False, True)
    447         for f, model in self.get_all_related_objects_with_model():

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\options.pyc in get_all_related_m2m_objects_with_model(self)
    559             cache = self._related_many_to_many_cache
    560         except AttributeError:
--> 561             cache = self._fill_related_many_to_many_cache()
    562         return list(six.iteritems(cache))
    563 

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\db\models\options.pyc in _fill_related_many_to_many_cache(self)
    573                 else:
    574                     cache[obj] = model
--> 575         for klass in self.apps.get_models():
    576             if not klass._meta.swapped:
    577                 for f in klass._meta.local_many_to_many:

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\utils\lru_cache.pyc in wrapper(*args, **kwds)
     99                         stats[HITS] += 1
    100                         return result
--> 101                     result = user_function(*args, **kwds)
    102                     cache[key] = result
    103                     stats[MISSES] += 1

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\apps\registry.pyc in get_models(self, app_mod, include_auto_created, include_deferred, include_swapped)
    166         Set the corresponding keyword argument to True to include such models.
    167         """
--> 168         self.check_models_ready()
    169         if app_mod:
    170             warnings.warn(

C:\Python\lib\site-packages\django-1.7c1-py2.7.egg\django\apps\registry.pyc in check_models_ready(self)
    129         """
    130         if not self.models_ready:
--> 131             raise AppRegistryNotReady("Models aren't loaded yet.")
    132 
    133     def get_app_configs(self):

AppRegistryNotReady: Models aren't loaded yet.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

Was dealing with this yesterday. Putting the following in my jupyter notebook before all the model imports helped circumvent and get back to fiddling:

import os, django
django.setup()

Relevant Modules

Django==1.10.1 django-debug-toolbar==1.8 django-extensions==1.8.1

ipykernel==4.6.1 ipython==6.1.0 ipython-genutils==0.2.0 ipywidgets==7.0.0

jupyter==1.0.0 jupyter-client==5.1.0 jupyter-console==5.2.0 jupyter-core==4.3.0