diff options
Diffstat (limited to 'django/apps/base.py')
| -rw-r--r-- | django/apps/base.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/django/apps/base.py b/django/apps/base.py index e0d637c96e..31d75bf5ed 100644 --- a/django/apps/base.py +++ b/django/apps/base.py @@ -109,6 +109,23 @@ class AppConfig(object): # Entry is a path to an app module. return cls(entry, module) + def get_model(self, model_name): + """ + Returns the model with the given case-insensitive model_name. + + Raises LookupError if no model exists with this name. + + This method assumes that apps.populate_models() has run. + """ + if self.models is None: + raise LookupError( + "App '%s' doesn't have any models." % self.label) + try: + return self.models[model_name.lower()] + except KeyError: + raise LookupError( + "App '%s' doesn't have a '%s' model." % (self.label, model_name)) + def import_models(self, all_models): # Dictionary of models for this app, primarily maintained in the # 'all_models' attribute of the Apps this AppConfig is attached to. |
