diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2012-11-24 13:43:20 +0800 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2012-11-24 14:26:50 +0800 |
| commit | 3fd8458fb3a30ea9fc6b3e7c08ff2d66a63e5067 (patch) | |
| tree | 44e51d51579cdd0d46ce909d6821c0ce8bf695e4 /django/db | |
| parent | 158a0332bfef38277ba0a6f7a89815624a7d0ea2 (diff) | |
[1.5.x] Fixed #19806 -- Ensure that content types and permissions aren't created for swapped models.
Thanks to rizumu for the report.
Backport of c8985a8a7317042a641e870cb75b3005cc5d67b1.
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/models/loading.py | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/django/db/models/loading.py b/django/db/models/loading.py index 8a0e796f4b..a0510acc6d 100644 --- a/django/db/models/loading.py +++ b/django/db/models/loading.py @@ -24,24 +24,24 @@ class AppCache(object): # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531. __shared_state = dict( # Keys of app_store are the model modules for each application. - app_store = SortedDict(), + app_store=SortedDict(), # Mapping of installed app_labels to model modules for that app. - app_labels = {}, + app_labels={}, # Mapping of app_labels to a dictionary of model names to model code. # May contain apps that are not installed. - app_models = SortedDict(), + app_models=SortedDict(), # Mapping of app_labels to errors raised when trying to import the app. - app_errors = {}, + app_errors={}, # -- Everything below here is only used when populating the cache -- - loaded = False, - handled = {}, - postponed = [], - nesting_level = 0, - _get_models_cache = {}, + loaded=False, + handled={}, + postponed=[], + nesting_level=0, + _get_models_cache={}, ) def __init__(self): @@ -167,7 +167,7 @@ class AppCache(object): def get_models(self, app_mod=None, include_auto_created=False, include_deferred=False, - only_installed=True): + only_installed=True, include_swapped=False): """ Given a module containing models, returns a list of the models. Otherwise returns a list of all installed models. @@ -179,8 +179,16 @@ class AppCache(object): 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. + + By default, models that aren't part of installed apps will *not* + be included in the list of models. However, if you specify + only_installed=False, they will be. + + By default, models that have been swapped out will *not* be + included in the list of models. However, if you specify + include_swapped, they will be. """ - cache_key = (app_mod, include_auto_created, include_deferred, only_installed) + cache_key = (app_mod, include_auto_created, include_deferred, only_installed, include_swapped) try: return self._get_models_cache[cache_key] except KeyError: @@ -203,7 +211,8 @@ class AppCache(object): 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)) + (not model._meta.auto_created or include_auto_created) and + (not model._meta.swapped or include_swapped)) ) self._get_models_cache[cache_key] = model_list return model_list |
