From 70c9654d454fe7a2206319a20e0b4158a6de639d Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Thu, 19 Dec 2013 21:36:02 +0100 Subject: [PATCH] Renamed registered_model to has_model. This avoids possible confusion with register_model. Thanks Marc Tamlyn for the suggestion. --- django/core/apps/cache.py | 6 +++--- django/db/models/base.py | 4 ++-- django/db/models/fields/related.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/django/core/apps/cache.py b/django/core/apps/cache.py index 0eddbed935..41196e5f05 100644 --- a/django/core/apps/cache.py +++ b/django/core/apps/cache.py @@ -298,12 +298,12 @@ class AppCache(object): models[model_name] = model self._get_models_cache.clear() - def registered_model(self, app_label, model_name): + def has_model(self, app_label, model_name): """ - Test if a model is registered and return the model class or None. + Returns the model class if one is registered and None otherwise. It's safe to call this method at import time, even while the app cache - is being populated. + is being populated. It returns None for models that aren't loaded yet. """ return self.all_models[app_label].get(model_name.lower()) diff --git a/django/db/models/base.py b/django/db/models/base.py index d1e7323d17..5599d81b4b 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -151,7 +151,7 @@ class ModelBase(type): new_class._base_manager = new_class._base_manager._copy_to_model(new_class) # Bail out early if we have already created this class. - m = new_class._meta.app_cache.registered_model(new_class._meta.app_label, name) + m = new_class._meta.app_cache.has_model(new_class._meta.app_label, name) if m is not None: return m @@ -278,7 +278,7 @@ class ModelBase(type): # the first time this model tries to register with the framework. There # should only be one class for each model, so we always return the # registered version. - return new_class._meta.app_cache.registered_model(new_class._meta.app_label, name) + return new_class._meta.app_cache.has_model(new_class._meta.app_label, name) def copy_managers(cls, base_managers): # This is in-place sorting of an Options attribute, but that's fine. diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index cf35504afe..0218c8c693 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -68,7 +68,7 @@ def add_lazy_relation(cls, field, relation, operation): # string right away. If get_model returns None, it means that the related # model isn't loaded yet, so we need to pend the relation until the class # is prepared. - model = cls._meta.app_cache.registered_model(app_label, model_name) + model = cls._meta.app_cache.has_model(app_label, model_name) if model: operation(field, model, cls) else: