MCPcopy
hub / github.com/django/django / resolve_relation

Function resolve_relation

django/db/models/fields/related.py:52–74  ·  view source on GitHub ↗

Transform relation into a model or fully-qualified model string of the form "app_label.ModelName", relative to scope_model. The relation argument can be: * RECURSIVE_RELATIONSHIP_CONSTANT, i.e. the string "self", in which case the model argument will be returned. *

(scope_model, relation)

Source from the content-addressed store, hash-verified

50
51
52def resolve_relation(scope_model, relation):
53 """
54 Transform relation into a model or fully-qualified model string of the form
55 "app_label.ModelName", relative to scope_model.
56
57 The relation argument can be:
58 * RECURSIVE_RELATIONSHIP_CONSTANT, i.e. the string "self", in which case
59 the model argument will be returned.
60 * A bare model name without an app_label, in which case scope_model's
61 app_label will be prepended.
62 * An "app_label.ModelName" string.
63 * A model class, which will be returned unchanged.
64 """
65 # Check for recursive relations
66 if relation == RECURSIVE_RELATIONSHIP_CONSTANT:
67 relation = scope_model
68
69 # Look for an "app.Model" relation
70 if isinstance(relation, str):
71 if "." not in relation:
72 relation = "%s.%s" % (scope_model._meta.app_label, relation)
73
74 return relation
75
76
77def lazy_related_operation(function, model, *related_models, **kwargs):

Callers 4

__new__Method · 0.90
lazy_related_operationFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected