Loading django/db/migrations/state.py +18 −13 Original line number Diff line number Diff line Loading @@ -44,11 +44,13 @@ class ProjectState(object): # Any apps in self.real_apps should have all their models included # in the render. We don't use the original model instances as there # are some variables that refer to the Apps object. # FKs/M2Ms from real apps are also not included as they just # mess things up with partial states (due to lack of dependencies) real_models = [] for app_label in self.real_apps: app = global_apps.get_app_config(app_label) for model in app.get_models(): real_models.append(ModelState.from_model(model)) real_models.append(ModelState.from_model(model, exclude_rels=True)) # Populate the app registry with a stub for each application. app_labels = set(model_state.app_label for model_state in self.models.values()) self.apps = Apps([AppConfigStub(label) for label in sorted(self.real_apps + list(app_labels))]) Loading Loading @@ -155,13 +157,15 @@ class ModelState(object): ) @classmethod def from_model(cls, model): def from_model(cls, model, exclude_rels=False): """ Feed me a model, get a ModelState representing it out. """ # Deconstruct the fields fields = [] for field in model._meta.local_fields: if getattr(field, "rel", None) and exclude_rels: continue name, path, args, kwargs = field.deconstruct() field_class = import_string(path) try: Loading @@ -173,6 +177,7 @@ class ModelState(object): model._meta.object_name, e, )) if not exclude_rels: for field in model._meta.local_many_to_many: name, path, args, kwargs = field.deconstruct() field_class = import_string(path) Loading tests/migrations/migrations_test_apps/migrated_app/__init__.py 0 → 100644 +0 −0 Empty file added. tests/migrations/migrations_test_apps/migrated_app/migrations/0001_initial.py 0 → 100644 +30 −0 Original line number Diff line number Diff line # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import migrations, models class Migration(migrations.Migration): operations = [ migrations.CreateModel( "Author", [ ("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=255)), ("slug", models.SlugField(null=True)), ("age", models.IntegerField(default=0)), ("silly_field", models.BooleanField(default=False)), ], ), migrations.CreateModel( "Tribble", [ ("id", models.AutoField(primary_key=True)), ("fluffy", models.BooleanField(default=True)), ], ) ] tests/migrations/migrations_test_apps/migrated_app/migrations/__init__.py 0 → 100644 +0 −0 Empty file added. tests/migrations/migrations_test_apps/migrated_app/models.py 0 → 100644 +0 −0 Empty file added. Loading
django/db/migrations/state.py +18 −13 Original line number Diff line number Diff line Loading @@ -44,11 +44,13 @@ class ProjectState(object): # Any apps in self.real_apps should have all their models included # in the render. We don't use the original model instances as there # are some variables that refer to the Apps object. # FKs/M2Ms from real apps are also not included as they just # mess things up with partial states (due to lack of dependencies) real_models = [] for app_label in self.real_apps: app = global_apps.get_app_config(app_label) for model in app.get_models(): real_models.append(ModelState.from_model(model)) real_models.append(ModelState.from_model(model, exclude_rels=True)) # Populate the app registry with a stub for each application. app_labels = set(model_state.app_label for model_state in self.models.values()) self.apps = Apps([AppConfigStub(label) for label in sorted(self.real_apps + list(app_labels))]) Loading Loading @@ -155,13 +157,15 @@ class ModelState(object): ) @classmethod def from_model(cls, model): def from_model(cls, model, exclude_rels=False): """ Feed me a model, get a ModelState representing it out. """ # Deconstruct the fields fields = [] for field in model._meta.local_fields: if getattr(field, "rel", None) and exclude_rels: continue name, path, args, kwargs = field.deconstruct() field_class = import_string(path) try: Loading @@ -173,6 +177,7 @@ class ModelState(object): model._meta.object_name, e, )) if not exclude_rels: for field in model._meta.local_many_to_many: name, path, args, kwargs = field.deconstruct() field_class = import_string(path) Loading
tests/migrations/migrations_test_apps/migrated_app/migrations/0001_initial.py 0 → 100644 +30 −0 Original line number Diff line number Diff line # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import migrations, models class Migration(migrations.Migration): operations = [ migrations.CreateModel( "Author", [ ("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=255)), ("slug", models.SlugField(null=True)), ("age", models.IntegerField(default=0)), ("silly_field", models.BooleanField(default=False)), ], ), migrations.CreateModel( "Tribble", [ ("id", models.AutoField(primary_key=True)), ("fluffy", models.BooleanField(default=True)), ], ) ]
tests/migrations/migrations_test_apps/migrated_app/migrations/__init__.py 0 → 100644 +0 −0 Empty file added.