mirror of https://github.com/django/django.git
Fixed #33572 -- Implemented CreateModel/AlterModelManagers reduction.
This commit is contained in:
parent
71017a68a6
commit
8f7cda0831
|
@ -170,6 +170,19 @@ class CreateModel(ModelOperation):
|
|||
managers=self.managers,
|
||||
),
|
||||
]
|
||||
elif (
|
||||
isinstance(operation, AlterModelManagers)
|
||||
and self.name_lower == operation.name_lower
|
||||
):
|
||||
return [
|
||||
CreateModel(
|
||||
self.name,
|
||||
fields=self.fields,
|
||||
options=self.options,
|
||||
bases=self.bases,
|
||||
managers=operation.managers,
|
||||
),
|
||||
]
|
||||
elif (
|
||||
isinstance(operation, AlterTogetherOptionOperation)
|
||||
and self.name_lower == operation.name_lower
|
||||
|
|
|
@ -129,6 +129,30 @@ class OptimizerTests(SimpleTestCase):
|
|||
],
|
||||
)
|
||||
|
||||
def test_create_alter_model_managers(self):
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
migrations.CreateModel("Foo", fields=[]),
|
||||
migrations.AlterModelManagers(
|
||||
name="Foo",
|
||||
managers=[
|
||||
("objects", models.Manager()),
|
||||
("things", models.Manager()),
|
||||
],
|
||||
),
|
||||
],
|
||||
[
|
||||
migrations.CreateModel(
|
||||
"Foo",
|
||||
fields=[],
|
||||
managers=[
|
||||
("objects", models.Manager()),
|
||||
("things", models.Manager()),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_create_model_and_remove_model_options(self):
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
|
|
Loading…
Reference in New Issue