MCPcopy
hub / github.com/django/django / make_model_tuple

Function make_model_tuple

django/db/models/utils.py:5–25  ·  view source on GitHub ↗

Take a model or a string of the form "app_label.ModelName" and return a corresponding ("app_label", "modelname") tuple. If a tuple is passed in, assume it's a valid model tuple already and return it unchanged.

(model)

Source from the content-addressed store, hash-verified

3
4
5def make_model_tuple(model):
6 """
7 Take a model or a string of the form "app_label.ModelName" and return a
8 corresponding ("app_label", "modelname") tuple. If a tuple is passed in,
9 assume it's a valid model tuple already and return it unchanged.
10 """
11 try:
12 if isinstance(model, tuple):
13 model_tuple = model
14 elif isinstance(model, str):
15 app_label, model_name = model.split(".")
16 model_tuple = app_label, model_name.lower()
17 else:
18 model_tuple = model._meta.app_label, model._meta.model_name
19 assert len(model_tuple) == 2
20 return model_tuple
21 except (ValueError, AssertionError):
22 raise ValueError(
23 "Invalid model reference '%s'. String model references "
24 "must be of the form 'app_label.ModelName'." % model
25 )
26
27
28def resolve_callables(mapping):

Callers 7

__init__Method · 0.90
_lazy_methodMethod · 0.90
__new__Method · 0.90
lazy_related_operationFunction · 0.90

Calls 1

splitMethod · 0.45

Tested by

no test coverage detected