diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-12-22 06:01:23 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-12-22 06:01:23 +0000 |
| commit | 3d00992d9fefdcdc3bbc3fc85c1a409350391e5c (patch) | |
| tree | 7a4a27587efc46830a6ab1a621e297482ea5c9fd /django/db/models/loading.py | |
| parent | 15f42cc92a865dd0f3a39e73e9ffdd6262bde7dd (diff) | |
Fixed #11936 -- Removed deferred models from the list returned by the app_cache. Thanks to ryszard for the report, and clamothe for the initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11938 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/loading.py')
| -rw-r--r-- | django/db/models/loading.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/django/db/models/loading.py b/django/db/models/loading.py index f86b691cc9..fbded9afd2 100644 --- a/django/db/models/loading.py +++ b/django/db/models/loading.py @@ -132,7 +132,7 @@ class AppCache(object): self._populate() return self.app_errors - def get_models(self, app_mod=None, include_auto_created=False): + def get_models(self, app_mod=None, include_auto_created=False, include_deferred=False): """ Given a module containing models, returns a list of the models. Otherwise returns a list of all installed models. @@ -140,21 +140,28 @@ class AppCache(object): By default, auto-created models (i.e., m2m models without an explicit intermediate table) are not included. However, if you specify include_auto_created=True, they will be. + + By default, models created to satisfy deferred attribute + queries are *not* included in the list of models. However, if + you specify include_deferred, they will be. """ - cache_key = (app_mod, include_auto_created) + cache_key = (app_mod, include_auto_created, include_deferred) try: return self._get_models_cache[cache_key] except KeyError: pass self._populate() if app_mod: - model_list = self.app_models.get(app_mod.__name__.split('.')[-2], SortedDict()).values() + app_list = [self.app_models.get(app_mod.__name__.split('.')[-2], SortedDict())] else: - model_list = [] - for app_entry in self.app_models.itervalues(): - model_list.extend(app_entry.values()) - if not include_auto_created: - model_list = filter(lambda o: not o._meta.auto_created, model_list) + app_list = self.app_models.itervalues() + model_list = [] + for app in app_list: + model_list.extend( + model for model in app.values() + if ((not model._deferred or include_deferred) + and (not model._meta.auto_created or include_auto_created)) + ) self._get_models_cache[cache_key] = model_list return model_list |
