summaryrefslogtreecommitdiff
path: root/django/apps/cache.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-12-13 21:29:30 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-12-17 10:17:45 +0100
commitebda5800aeef3f3158b53aa28b3d503bc972a9a7 (patch)
treeb8ae095d7826ef7f185b2a6e53ecdbe877e64003 /django/apps/cache.py
parente85932b54ebc4f03df008accafb2c8acb37361d4 (diff)
Simplified register_models.
Since it's never called with more than one model at a time the current signature is needlessly complicated.
Diffstat (limited to 'django/apps/cache.py')
-rw-r--r--django/apps/cache.py57
1 files changed, 31 insertions, 26 deletions
diff --git a/django/apps/cache.py b/django/apps/cache.py
index 32c57371cb..b125d6b4c6 100644
--- a/django/apps/cache.py
+++ b/django/apps/cache.py
@@ -302,32 +302,27 @@ class BaseAppCache(object):
except KeyError:
return None
- def register_models(self, app_label, *models):
- """
- Register a set of models as belonging to an app.
- """
- if models:
- try:
- app_config = self.app_configs[app_label]
- except KeyError:
- app_config = AppConfig._stub(app_label)
- self.app_configs[app_label] = app_config
- for model in models:
- # Add the model to the app_config's models dictionary.
- model_name = model._meta.model_name
- model_dict = app_config.models
- if model_name in model_dict:
- # The same model may be imported via different paths (e.g.
- # appname.models and project.appname.models). We use the source
- # filename as a means to detect identity.
- fname1 = os.path.abspath(upath(sys.modules[model.__module__].__file__))
- fname2 = os.path.abspath(upath(sys.modules[model_dict[model_name].__module__].__file__))
- # Since the filename extension could be .py the first time and
- # .pyc or .pyo the second time, ignore the extension when
- # comparing.
- if os.path.splitext(fname1)[0] == os.path.splitext(fname2)[0]:
- continue
- model_dict[model_name] = model
+ def register_model(self, app_label, model):
+ try:
+ app_config = self.app_configs[app_label]
+ except KeyError:
+ app_config = AppConfig._stub(app_label)
+ self.app_configs[app_label] = app_config
+ # Add the model to the app_config's models dictionary.
+ model_name = model._meta.model_name
+ model_dict = app_config.models
+ if model_name in model_dict:
+ # The same model may be imported via different paths (e.g.
+ # appname.models and project.appname.models). We use the source
+ # filename as a means to detect identity.
+ fname1 = os.path.abspath(upath(sys.modules[model.__module__].__file__))
+ fname2 = os.path.abspath(upath(sys.modules[model_dict[model_name].__module__].__file__))
+ # Since the filename extension could be .py the first time and
+ # .pyc or .pyo the second time, ignore the extension when
+ # comparing.
+ if os.path.splitext(fname1)[0] == os.path.splitext(fname2)[0]:
+ return
+ model_dict[model_name] = model
self._get_models_cache.clear()
def set_available_apps(self, available):
@@ -383,6 +378,16 @@ class BaseAppCache(object):
app_paths.append(self._get_app_path(app))
return app_paths
+ def register_models(self, app_label, *models):
+ """
+ Register a set of models as belonging to an app.
+ """
+ warnings.warn(
+ "register_models(app_label, models) is deprecated.",
+ PendingDeprecationWarning, stacklevel=2)
+ for model in models:
+ self.register_model(app_label, model)
+
class AppCache(BaseAppCache):
"""