MCPcopy
hub / github.com/django/django / __init__

Method __init__

django/apps/registry.py:20–59  ·  view source on GitHub ↗
(self, installed_apps=())

Source from the content-addressed store, hash-verified

18 """
19
20 def __init__(self, installed_apps=()):
21 # installed_apps is set to None when creating the main registry
22 # because it cannot be populated at that point. Other registries must
23 # provide a list of installed apps and are populated immediately.
24 if installed_apps is None and hasattr(sys.modules[__name__], "apps"):
25 raise RuntimeError("You must supply an installed_apps argument.")
26
27 # Mapping of app labels => model names => model classes. Every time a
28 # model is imported, ModelBase.__new__ calls apps.register_model which
29 # creates an entry in all_models. All imported models are registered,
30 # regardless of whether they're defined in an installed application
31 # and whether the registry has been populated. Since it isn't possible
32 # to reimport a module safely (it could reexecute initialization code)
33 # all_models is never overridden or reset.
34 self.all_models = defaultdict(dict)
35
36 # Mapping of labels to AppConfig instances for installed apps.
37 self.app_configs = {}
38
39 # Stack of app_configs. Used to store the current state in
40 # set_available_apps and set_installed_apps.
41 self.stored_app_configs = []
42
43 # Whether the registry is populated.
44 self.apps_ready = self.models_ready = self.ready = False
45 # For the autoreloader.
46 self.ready_event = threading.Event()
47
48 # Lock for thread-safe population.
49 self._lock = threading.RLock()
50 self.loading = False
51
52 # Maps ("app_label", "modelname") tuples to lists of functions to be
53 # called when the corresponding model is ready. Used by this class's
54 # `lazy_model_operation()` and `do_pending_operations()` methods.
55 self._pending_operations = defaultdict(list)
56
57 # Populate apps and models, unless it's the main registry.
58 if installed_apps is not None:
59 self.populate(installed_apps)
60
61 def populate(self, installed_apps=None):
62 """

Callers

nothing calls this directly

Calls 1

populateMethod · 0.95

Tested by

no test coverage detected