| 213 | return app_config.get_model(model_name, require_ready=require_ready) |
| 214 | |
| 215 | def register_model(self, app_label, model): |
| 216 | # Since this method is called when models are imported, it cannot |
| 217 | # perform imports because of the risk of import loops. It mustn't |
| 218 | # call get_app_config(). |
| 219 | model_name = model._meta.model_name |
| 220 | app_models = self.all_models[app_label] |
| 221 | if model_name in app_models: |
| 222 | if ( |
| 223 | model.__name__ == app_models[model_name].__name__ |
| 224 | and model.__module__ == app_models[model_name].__module__ |
| 225 | ): |
| 226 | warnings.warn( |
| 227 | "Model '%s.%s' was already registered. Reloading models is not " |
| 228 | "advised as it can lead to inconsistencies, most notably with " |
| 229 | "related models." % (app_label, model_name), |
| 230 | RuntimeWarning, |
| 231 | stacklevel=2, |
| 232 | ) |
| 233 | else: |
| 234 | raise RuntimeError( |
| 235 | "Conflicting '%s' models in application '%s': %s and %s." |
| 236 | % (model_name, app_label, app_models[model_name], model) |
| 237 | ) |
| 238 | app_models[model_name] = model |
| 239 | self.do_pending_operations(model) |
| 240 | self.clear_cache() |
| 241 | |
| 242 | def is_installed(self, app_name): |
| 243 | """ |