MCPcopy
hub / github.com/django/django / lazy_related_operation

Function lazy_related_operation

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

Schedule `function` to be called once `model` and all `related_models` have been imported and registered with the app registry. `function` will be called with the newly-loaded model classes as its positional arguments, plus any optional keyword arguments. The `model` argument m

(function, model, *related_models, **kwargs)

Source from the content-addressed store, hash-verified

75
76
77def lazy_related_operation(function, model, *related_models, **kwargs):
78 """
79 Schedule `function` to be called once `model` and all `related_models`
80 have been imported and registered with the app registry. `function` will
81 be called with the newly-loaded model classes as its positional arguments,
82 plus any optional keyword arguments.
83
84 The `model` argument must be a model class. Each subsequent positional
85 argument is another model, or a reference to another model - see
86 `resolve_relation()` for the various forms these may take. Any relative
87 references will be resolved relative to `model`.
88
89 This is a convenience wrapper for `Apps.lazy_model_operation` - the app
90 registry model used is the one found in `model._meta.apps`.
91 """
92 models = [model] + [resolve_relation(model, rel) for rel in related_models]
93 model_keys = (make_model_tuple(m) for m in models)
94 apps = model._meta.apps
95 return apps.lazy_model_operation(partial(function, **kwargs), *model_keys)
96
97
98class RelatedField(FieldCacheMixin, Field):

Callers 5

contribute_to_classMethod · 0.90
_prepareMethod · 0.90
contribute_to_classMethod · 0.85
contribute_to_classMethod · 0.85

Calls 3

make_model_tupleFunction · 0.90
lazy_model_operationMethod · 0.80
resolve_relationFunction · 0.70

Tested by

no test coverage detected