A registry that stores the configuration of installed applications.
It also keeps track of models, e.g. to provide reverse relations.
Method | __init__ |
Undocumented |
Method | check_apps_ready |
Raise an exception if all apps haven't been imported yet. |
Method | check_models_ready |
Raise an exception if all models haven't been imported yet. |
Method | clear_cache |
Clear all internal caches, for methods that alter the app registry. |
Method | do_pending_operations |
Take a newly-prepared model and pass it to each function waiting for it. This is called at the very end of Apps.register_model(). |
Method | get_app_config |
Import applications and returns an app config for the given label. |
Method | get_app_configs |
Import applications and return an iterable of app configs. |
Method | get_containing_app_config |
Look for an app config containing a given object. |
Method | get_model |
Return the model matching the given app_label and model_name. |
Method | get_models |
Return a list of all installed models. |
Method | get_registered_model |
Similar to get_model(), but doesn't require that an app exists with the given app_label. |
Method | get_swappable_settings_name |
For a given model string (e.g. "auth.User"), return the name of the corresponding settings name if it refers to a swappable model. If the referred model is not swappable, return None. |
Method | is_installed |
Check whether an application with this name exists in the registry. |
Method | lazy_model_operation |
Take a function and a number of ("app_label", "modelname") tuples, and when all the corresponding models have been imported and registered, call the function with the model classes as its arguments. |
Method | populate |
Load application configurations and models. |
Method | register_model |
Undocumented |
Method | set_available_apps |
Restrict the set of installed apps used by get_app_config[s]. |
Method | set_installed_apps |
Enable a different set of installed apps for get_app_config[s]. |
Method | unset_available_apps |
Cancel a previous call to set_available_apps(). |
Method | unset_installed_apps |
Cancel a previous call to set_installed_apps(). |
Instance Variable | _lock |
Undocumented |
Instance Variable | _pending_operations |
Undocumented |
Instance Variable | all_models |
Undocumented |
Instance Variable | app_configs |
Undocumented |
Instance Variable | apps_ready |
Undocumented |
Instance Variable | loading |
Undocumented |
Instance Variable | models_ready |
Undocumented |
Instance Variable | ready |
Undocumented |
Instance Variable | ready_event |
Undocumented |
Instance Variable | stored_app_configs |
Undocumented |
django.db.migrations.state.StateApps
Undocumented
Clear all internal caches, for methods that alter the app registry.
This is mostly used in tests.
Import applications and returns an app config for the given label.
Raise LookupError if no application exists with this label.
Look for an app config containing a given object.
object_name is the dotted Python path to the object.
Return the app config for the inner application in case of nesting. Return None if the object isn't in any registered app config.
Return the model matching the given app_label and model_name.
As a shortcut, app_label may be in the form <app_label>.<model_name>.
model_name is case-insensitive.
Raise LookupError if no application exists with this label, or no model exists with this name in the application. Raise ValueError if called with a single argument that doesn't contain exactly one dot.
Return a list of all installed models.
By default, the following models aren't included:
Set the corresponding keyword argument to True to include such models.
Similar to get_model(), but doesn't require that an app exists with the given app_label.
It's safe to call this method at import time, even while the registry is being populated.
For a given model string (e.g. "auth.User"), return the name of the corresponding settings name if it refers to a swappable model. If the referred model is not swappable, return None.
This method is decorated with lru_cache because it's performance critical when it comes to migrations. Since the swappable settings don't change after Django has loaded the settings, there is no reason to get the respective settings attribute over and over again.
Check whether an application with this name exists in the registry.
app_name is the full name of the app e.g. 'django.contrib.admin'.
Take a function and a number of ("app_label", "modelname") tuples, and when all the corresponding models have been imported and registered, call the function with the model classes as its arguments.
The function passed to this method must accept exactly n models as arguments, where n=len(model_keys).
Load application configurations and models.
Import each application module and then each model module.
It is thread-safe and idempotent, but not reentrant.
django.db.migrations.state.StateApps
Undocumented
Restrict the set of installed apps used by get_app_config[s].
available must be an iterable of application names.
set_available_apps() must be balanced with unset_available_apps().
Primarily used for performance optimization in TransactionTestCase.
This method is safe in the sense that it doesn't trigger any imports.
Enable a different set of installed apps for get_app_config[s].
installed must be an iterable in the same format as INSTALLED_APPS.
set_installed_apps() must be balanced with unset_installed_apps(), even if it exits with an exception.
Primarily used as a receiver of the setting_changed signal in tests.
This method may trigger new imports, which may add new models to the registry of all imported models. They will stay in the registry even after unset_installed_apps(). Since it isn't possible to replay imports safely (e.g. that could lead to registering listeners twice), models are registered when they're imported and never removed.