Fixed #27717 -- Allowed migration optimization across AlterModelOptions.

This commit is contained in:
Ed Morley 2017-01-10 23:38:48 +00:00 committed by Tim Graham
parent 6872ce2266
commit 7156a6c9c4
2 changed files with 23 additions and 0 deletions

View File

@ -151,6 +151,18 @@ class CreateModel(ModelOperation):
managers=self.managers,
),
]
elif isinstance(operation, AlterModelOptions) and self.name_lower == operation.name_lower:
new_options = self.options.copy()
new_options.update(operation.options)
return [
CreateModel(
self.name,
fields=self.fields,
options=new_options,
bases=self.bases,
managers=self.managers,
),
]
elif isinstance(operation, FieldOperation) and self.name_lower == operation.model_name_lower:
if isinstance(operation, AddField):
# Don't allow optimizations of FKs through models they reference

View File

@ -101,6 +101,17 @@ class OptimizerTests(SimpleTestCase):
],
)
def test_create_alter_model_options(self):
self.assertOptimizesTo(
[
migrations.CreateModel('Foo', fields=[]),
migrations.AlterModelOptions(name='Foo', options={'verbose_name_plural': 'Foozes'}),
],
[
migrations.CreateModel('Foo', fields=[], options={'verbose_name_plural': 'Foozes'}),
]
)
def _test_create_alter_foo_delete_model(self, alter_foo):
"""
CreateModel, AlterModelTable, AlterUniqueTogether/AlterIndexTogether/