summaryrefslogtreecommitdiff
path: root/django/apps
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-01-26 12:46:28 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-01-26 13:01:09 +0100
commit3c47786cb91617b3757e57b6bfeda06ef14e561a (patch)
treec6060200e2c3fa98f7326f37ba199b671ba00e62 /django/apps
parent8e1fc0349124d4a792e02bfd4c90576f9e3bda95 (diff)
downloaddjango-3c47786cb91617b3757e57b6bfeda06ef14e561a.tar.gz
Fixed #21702 -- get_model('app_label.ModelName').
Also added tests for get_model.
Diffstat (limited to 'django/apps')
-rw-r--r--django/apps/registry.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/django/apps/registry.py b/django/apps/registry.py
index 649ba42d78..7cf5a2637b 100644
--- a/django/apps/registry.py
+++ b/django/apps/registry.py
@@ -170,16 +170,22 @@ class Apps(object):
include_auto_created, include_deferred, include_swapped)))
return result
- def get_model(self, app_label, model_name):
+ def get_model(self, app_label, model_name=None):
"""
Returns the model matching the given app_label and model_name.
+ As a shortcut, this function also accepts a single argument in the
+ form <app_label>.<model_name>.
+
model_name is case-insensitive.
Raises LookupError if no application exists with this label, or no
- model exists with this name in the application.
+ model exists with this name in the application. Raises ValueError if
+ called with a single argument that doesn't contain exactly one dot.
"""
self.check_ready()
+ if model_name is None:
+ app_label, model_name = app_label.split('.')
return self.get_app_config(app_label).get_model(model_name.lower())
def register_model(self, app_label, model):