Loading django/apps/base.py +1 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ class AppConfig(object): self.models_module = models_module # Mapping of lower case model names to model classes. # Populated by AppCache.register_models(). # Populated by calls to AppCache.register_model(). self.models = OrderedDict() # Whether the app is in INSTALLED_APPS or was automatically created Loading django/apps/cache.py +31 −26 Original line number Diff line number Diff line Loading @@ -302,17 +302,12 @@ 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: 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 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 Loading @@ -326,7 +321,7 @@ class BaseAppCache(object): # .pyc or .pyo the second time, ignore the extension when # comparing. if os.path.splitext(fname1)[0] == os.path.splitext(fname2)[0]: continue return model_dict[model_name] = model self._get_models_cache.clear() Loading Loading @@ -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): """ Loading django/db/models/base.py +1 −1 Original line number Diff line number Diff line Loading @@ -274,7 +274,7 @@ class ModelBase(type): new_class._prepare() new_class._meta.app_cache.register_models(new_class._meta.app_label, new_class) new_class._meta.app_cache.register_model(new_class._meta.app_label, new_class) # Because of the way imports happen (recursively), we may or may not be # 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 Loading tests/migrations/test_commands.py +2 −2 Original line number Diff line number Diff line Loading @@ -151,7 +151,7 @@ class MakeMigrationsTests(MigrationTestBase): def test_files_content(self): self.assertTableNotExists("migrations_unicodemodel") app_cache.register_models('migrations', UnicodeModel) app_cache.register_model('migrations', UnicodeModel) with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}): call_command("makemigrations", "migrations", verbosity=0) Loading Loading @@ -187,7 +187,7 @@ class MakeMigrationsTests(MigrationTestBase): def test_failing_migration(self): #21280 - If a migration fails to serialize, it shouldn't generate an empty file. app_cache.register_models('migrations', UnserializableModel) app_cache.register_model('migrations', UnserializableModel) with six.assertRaisesRegex(self, ValueError, r'Cannot serialize'): with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}): Loading Loading
django/apps/base.py +1 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ class AppConfig(object): self.models_module = models_module # Mapping of lower case model names to model classes. # Populated by AppCache.register_models(). # Populated by calls to AppCache.register_model(). self.models = OrderedDict() # Whether the app is in INSTALLED_APPS or was automatically created Loading
django/apps/cache.py +31 −26 Original line number Diff line number Diff line Loading @@ -302,17 +302,12 @@ 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: 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 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 Loading @@ -326,7 +321,7 @@ class BaseAppCache(object): # .pyc or .pyo the second time, ignore the extension when # comparing. if os.path.splitext(fname1)[0] == os.path.splitext(fname2)[0]: continue return model_dict[model_name] = model self._get_models_cache.clear() Loading Loading @@ -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): """ Loading
django/db/models/base.py +1 −1 Original line number Diff line number Diff line Loading @@ -274,7 +274,7 @@ class ModelBase(type): new_class._prepare() new_class._meta.app_cache.register_models(new_class._meta.app_label, new_class) new_class._meta.app_cache.register_model(new_class._meta.app_label, new_class) # Because of the way imports happen (recursively), we may or may not be # 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 Loading
tests/migrations/test_commands.py +2 −2 Original line number Diff line number Diff line Loading @@ -151,7 +151,7 @@ class MakeMigrationsTests(MigrationTestBase): def test_files_content(self): self.assertTableNotExists("migrations_unicodemodel") app_cache.register_models('migrations', UnicodeModel) app_cache.register_model('migrations', UnicodeModel) with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}): call_command("makemigrations", "migrations", verbosity=0) Loading Loading @@ -187,7 +187,7 @@ class MakeMigrationsTests(MigrationTestBase): def test_failing_migration(self): #21280 - If a migration fails to serialize, it shouldn't generate an empty file. app_cache.register_models('migrations', UnserializableModel) app_cache.register_model('migrations', UnserializableModel) with six.assertRaisesRegex(self, ValueError, r'Cannot serialize'): with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}): Loading