diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-28 20:13:08 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-28 20:37:42 +0100 |
| commit | bbdf01e00aed1e86f6aaeba81065be21af35d415 (patch) | |
| tree | b4bc4b0ebf1bebaf4636c764f43ee48cd2686d7a /django/db/migrations | |
| parent | 81a5e35c8d357051e558e6f0d1b6ff7a7523a537 (diff) | |
Populated non-master app registries.
This removes the gap between the master app registry and ad-hoc app
registries created by the migration framework, specifically in terms
of behavior of the get_model[s] methods.
This commit contains a stealth feature that I'd rather not describe.
Diffstat (limited to 'django/db/migrations')
| -rw-r--r-- | django/db/migrations/state.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py index 198b2c516c..21009f4da5 100644 --- a/django/db/migrations/state.py +++ b/django/db/migrations/state.py @@ -1,3 +1,4 @@ +from django.apps import AppConfig from django.apps.registry import Apps from django.db import models from django.db.models.options import DEFAULT_NAMES, normalize_unique_together @@ -33,6 +34,11 @@ class ProjectState(object): "Turns the project state into actual models in a new Apps" if self.apps is None: self.apps = Apps() + # Populate the app registry with a stub for each application. + app_labels = set(model_state.app_label for model_state in self.models.values()) + app_configs = [AppConfigStub(label) for label in sorted(app_labels)] + self.apps.populate_apps(app_configs) + self.apps.populate_models() # We keep trying to render the models in a loop, ignoring invalid # base errors, until the size of the unrendered models doesn't # decrease by at least one, meaning there's a base dependency loop/ @@ -68,6 +74,19 @@ class ProjectState(object): return not (self == other) +class AppConfigStub(AppConfig): + """ + Stubs a Django AppConfig. Only provides a label and a dict of models. + """ + def __init__(self, label): + self.label = label + self.path = None + super(AppConfigStub, self).__init__(None, None) + + def import_models(self, all_models): + self.models = all_models + + class ModelState(object): """ Represents a Django Model. We don't use the actual Model class |
