Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Un-borg-ify AppCache

  • Loading branch information...
commit dbc17d035b255a4da977251fe399f5c80cffeecd 1 parent 7e8c64d
@andrewgodwin andrewgodwin authored
Showing with 12 additions and 20 deletions.
  1. +12 −20 django/db/models/loading.py
View
32 django/db/models/loading.py
@@ -14,37 +14,29 @@
__all__ = ('get_apps', 'get_app', 'get_models', 'get_model', 'register_models',
'load_app', 'app_cache_ready')
+
class AppCache(object):
"""
A cache that stores installed applications and their models. Used to
provide reverse-relations and for app introspection (e.g. admin).
"""
- # Use the Borg pattern to share state between all instances. Details at
- # 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(),
+ def __init__(self):
+ # Keys of app_store are the model modules for each application.
+ self.app_store = SortedDict()
# Mapping of installed app_labels to model modules for that app.
- app_labels = {},
-
+ self.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(),
-
+ self.app_models = SortedDict()
# Mapping of app_labels to errors raised when trying to import the app.
- app_errors = {},
-
+ self.app_errors = {}
# -- Everything below here is only used when populating the cache --
- loaded = False,
- handled = {},
- postponed = [],
- nesting_level = 0,
- _get_models_cache = {},
- )
-
- def __init__(self):
- self.__dict__ = self.__shared_state
+ self.loaded = False
+ self.handled = {}
+ self.postponed = []
+ self.nesting_level = 0
+ self._get_models_cache = {}
def _populate(self):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.