summaryrefslogtreecommitdiff
path: root/django/db/models/utils.py
diff options
context:
space:
mode:
authorAlex Hill <alex@hill.net.au>2015-03-03 16:43:56 +0800
committerTim Graham <timograham@gmail.com>2015-03-25 16:48:17 -0400
commit720ff740e70e649a97fcf0232fec132569a52c7e (patch)
tree688533ec18f1d970b8c7671ef94be83b67720b80 /django/db/models/utils.py
parent0f6f80c2e7736ec4e2aa40287fe8c37ffff0a783 (diff)
downloaddjango-720ff740e70e649a97fcf0232fec132569a52c7e.tar.gz
Fixed #24215 -- Refactored lazy model operations
This adds a new method, Apps.lazy_model_operation(), and a helper function, lazy_related_operation(), which together supersede add_lazy_relation() and make lazy model operations the responsibility of the App registry. This system no longer uses the class_prepared signal.
Diffstat (limited to 'django/db/models/utils.py')
-rw-r--r--django/db/models/utils.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/django/db/models/utils.py b/django/db/models/utils.py
new file mode 100644
index 0000000000..f696e30ce2
--- /dev/null
+++ b/django/db/models/utils.py
@@ -0,0 +1,18 @@
+from django.utils import six
+
+
+def make_model_tuple(model):
+ """
+ Takes a model or a string of the form "app_label.ModelName" and returns a
+ corresponding ("app_label", "modelname") tuple. If a tuple is passed in,
+ it's assumed to be a valid model tuple already and returned unchanged.
+ """
+ if isinstance(model, tuple):
+ model_tuple = model
+ elif isinstance(model, six.string_types):
+ app_label, model_name = model.split(".")
+ model_tuple = app_label, model_name.lower()
+ else:
+ model_tuple = model._meta.app_label, model._meta.model_name
+ assert len(model_tuple) == 2, "Invalid model representation: %s" % model
+ return model_tuple