diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-31 16:23:42 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-31 17:30:58 +0100 |
| commit | c40209dcc09f19524fb85251f39a4051491bbec0 (patch) | |
| tree | f7788f18e608acf0befab73b3391fea4c21a7066 /django/apps | |
| parent | 5dfec4e23b4a3b81f8ec19bf0cf45147ad6b18e5 (diff) | |
Made it possible to change an application's label in its configuration.
Fixed #21683.
Diffstat (limited to 'django/apps')
| -rw-r--r-- | django/apps/registry.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/django/apps/registry.py b/django/apps/registry.py index 317bde33fe..7ff1c6625d 100644 --- a/django/apps/registry.py +++ b/django/apps/registry.py @@ -201,6 +201,27 @@ class Apps(object): app_config = self.app_configs.get(app_name.rpartition(".")[2]) return app_config is not None and app_config.name == app_name + def get_containing_app_config(self, object_name): + """ + Look for an app config containing a given object. + + object_name is the dotted Python path to the object. + + Returns the app config for the inner application in case of nesting. + Returns None if the object isn't in any registered app config. + + It's safe to call this method at import time, even while the registry + is being populated. + """ + candidates = [] + for app_config in self.app_configs.values(): + if object_name.startswith(app_config.name): + subpath = object_name[len(app_config.name):] + if subpath == '' or subpath[0] == '.': + candidates.append(app_config) + if candidates: + return sorted(candidates, key=lambda ac: -len(ac.name))[0] + def get_registered_model(self, app_label, model_name): """ Similar to get_model(), but doesn't require that an app exists with |
