Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Seed the global app cache in a call to db.models.get_model() except w…

…hen we are

constructing a model class. Refs #2348.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3490 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9e957485bd99f0c4de457201f621fab7b63ad784 1 parent 1a3b112
@malcolmt malcolmt authored
Showing with 8 additions and 4 deletions.
  1. +2 −2 django/db/models/base.py
  2. +6 −2 django/db/models/loading.py
View
4 django/db/models/base.py
@@ -44,7 +44,7 @@ def __new__(cls, name, bases, attrs):
new_class._meta.app_label = model_module.__name__.split('.')[-2]
# Bail out early if we have already created this class.
- m = get_model(new_class._meta.app_label, name)
+ m = get_model(new_class._meta.app_label, name, False)
if m is not None:
return m
@@ -68,7 +68,7 @@ def __new__(cls, name, bases, attrs):
# the first class for this model to register with the framework. There
# should only be one class for each model, so we must always return the
# registered version.
- return get_model(new_class._meta.app_label, name)
+ return get_model(new_class._meta.app_label, name, False)
class Model(object):
__metaclass__ = ModelBase
View
8 django/db/models/loading.py
@@ -75,11 +75,15 @@ def get_models(app_mod=None):
model_list.extend(get_models(app_mod))
return model_list
-def get_model(app_label, model_name):
+def get_model(app_label, model_name, seed_cache = True):
"""
- Returns the model matching the given app_label and case-insensitive model_name.
+ Returns the model matching the given app_label and case-insensitive
+ model_name.
+
Returns None if no model is found.
"""
+ if seed_cache:
+ get_apps()
try:
model_dict = _app_models[app_label]
except KeyError:
Please sign in to comment.
Something went wrong with that request. Please try again.