summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2018-07-14 11:56:19 -0400
committerTim Graham <timograham@gmail.com>2018-07-19 17:42:18 -0400
commit1e9b02a4c28142303fb4d33632e77ff7e26acb8b (patch)
treed1aa4da9b55bfe87a7bfca99dfc969956e259bf3
parentfc16015de4ffa370919b0e36253bd415f796394b (diff)
Refs #28862 -- Removed the FieldRelatedOptionOperation.reduce() optimization.
It isn't required anymore since AlterTogetherOperations can be reduced into CreateModels which can reduce DeleteField operations.
-rw-r--r--django/db/migrations/operations/models.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py
index f286bf4ea4..18feb9b9a1 100644
--- a/django/db/migrations/operations/models.py
+++ b/django/db/migrations/operations/models.py
@@ -142,13 +142,22 @@ class CreateModel(ModelOperation):
managers=self.managers,
),
]
- elif isinstance(operation, FieldRelatedOptionOperation) and self.name_lower == operation.name_lower:
- option_value = getattr(operation, operation.option_name)
+ elif isinstance(operation, AlterTogetherOptionOperation) and self.name_lower == operation.name_lower:
return [
CreateModel(
self.name,
fields=self.fields,
- options={**self.options, **{operation.option_name: option_value}},
+ options={**self.options, **{operation.option_name: operation.option_value}},
+ bases=self.bases,
+ managers=self.managers,
+ ),
+ ]
+ elif isinstance(operation, AlterOrderWithRespectTo) and self.name_lower == operation.name_lower:
+ return [
+ CreateModel(
+ self.name,
+ fields=self.fields,
+ options={**self.options, 'order_with_respect_to': operation.order_with_respect_to},
bases=self.bases,
managers=self.managers,
),
@@ -481,17 +490,7 @@ class ModelOptionOperation(ModelOperation):
return super().reduce(operation, app_label=app_label)
-class FieldRelatedOptionOperation(ModelOptionOperation):
- def reduce(self, operation, app_label=None):
- if isinstance(operation, FieldOperation) and self.name_lower == operation.model_name_lower:
- if isinstance(operation, RemoveField):
- return False
- if not self.references_field(operation.model_name, operation.name):
- return [operation, self]
- return super().reduce(operation, app_label=app_label)
-
-
-class AlterTogetherOptionOperation(FieldRelatedOptionOperation):
+class AlterTogetherOptionOperation(ModelOptionOperation):
option_name = None
def __init__(self, name, option_value):
@@ -569,7 +568,7 @@ class AlterIndexTogether(AlterTogetherOptionOperation):
super().__init__(name, index_together)
-class AlterOrderWithRespectTo(FieldRelatedOptionOperation):
+class AlterOrderWithRespectTo(ModelOptionOperation):
"""Represent a change with the order_with_respect_to option."""
option_name = 'order_with_respect_to'