From 4cf1f2f13ee0927d63b48d0c7d8a8f532e0c0a1e Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Fri, 2 Aug 2019 17:19:55 +0100 Subject: [PATCH] Simplified AlterModelTable by making it subclass ModelOptionOperation. --- django/db/migrations/operations/models.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py index 3241f53d3c..66ecd606ee 100644 --- a/django/db/migrations/operations/models.py +++ b/django/db/migrations/operations/models.py @@ -428,7 +428,14 @@ class RenameModel(ModelOperation): ) -class AlterModelTable(ModelOperation): +class ModelOptionOperation(ModelOperation): + def reduce(self, operation, app_label=None): + if isinstance(operation, (self.__class__, DeleteModel)) and self.name_lower == operation.name_lower: + return [operation] + return super().reduce(operation, app_label=app_label) + + +class AlterModelTable(ModelOptionOperation): """Rename a model's table.""" def __init__(self, name, table): @@ -477,18 +484,6 @@ class AlterModelTable(ModelOperation): self.table if self.table is not None else "(default)" ) - def reduce(self, operation, app_label=None): - if isinstance(operation, (AlterModelTable, DeleteModel)) and self.name_lower == operation.name_lower: - return [operation] - return super().reduce(operation, app_label=app_label) - - -class ModelOptionOperation(ModelOperation): - def reduce(self, operation, app_label=None): - if isinstance(operation, (self.__class__, DeleteModel)) and self.name_lower == operation.name_lower: - return [operation] - return super().reduce(operation, app_label=app_label) - class AlterTogetherOptionOperation(ModelOptionOperation): option_name = None