magic-removal: Changed db.models.loading to make sure get_models() and get_model() both call get_apps() first to ensure _app_list cache is filled

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2394 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-02-25 19:35:30 +00:00
parent 52f84c0f63
commit 863bd3d36a
1 changed files with 3 additions and 1 deletions

View File

@ -34,11 +34,12 @@ def get_models(app_mod=None):
Given a module containing models, returns a list of the models. Otherwise Given a module containing models, returns a list of the models. Otherwise
returns a list of all installed models. returns a list of all installed models.
""" """
app_list = get_apps() # Run get_apps() to populate the _app_list cache. Slightly hackish.
if app_mod: if app_mod:
return _app_models.get(app_mod.__name__.split('.')[-2], {}).values() return _app_models.get(app_mod.__name__.split('.')[-2], {}).values()
else: else:
model_list = [] model_list = []
for app_mod in get_apps(): for app_mod in app_list:
model_list.extend(get_models(app_mod)) model_list.extend(get_models(app_mod))
return model_list return model_list
@ -47,6 +48,7 @@ def get_model(app_label, model_name):
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. Returns None if no model is found.
""" """
get_apps() # Run get_apps() to populate the _app_list cache. Slightly hackish.
try: try:
model_dict = _app_models[app_label] model_dict = _app_models[app_label]
except KeyError: except KeyError: