diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-12-22 11:20:43 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-12-22 11:20:43 +0000 |
| commit | 7d6213e0aa70340f4e3439abd43bc98427493bd8 (patch) | |
| tree | 6a6660e8edcb27fc0cfaec8948f9ced04cf66ec5 /django | |
| parent | b15d762d7a03477384efea992de18adc1d2500ea (diff) | |
[1.1.X] 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.
Backport of r11938 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11942 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/loading.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/django/db/models/loading.py b/django/db/models/loading.py index e07aab4efe..a1d83cd577 100644 --- a/django/db/models/loading.py +++ b/django/db/models/loading.py @@ -131,19 +131,27 @@ class AppCache(object): self._populate() return self.app_errors - def get_models(self, app_mod=None): + def get_models(self, app_mod=None, include_deferred=False): """ Given a module containing models, returns a list of the models. Otherwise returns a list of all installed models. + + 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. """ self._populate() if app_mod: - return 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()) - return 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) + ) + return model_list def get_model(self, app_label, model_name, seed_cache=True): """ |
