Simplified AlterModelTable by making it subclass ModelOptionOperation.

This commit is contained in:
Nick Pope 2019-08-02 17:19:55 +01:00 committed by Mariusz Felisiak
parent 75f8264083
commit 4cf1f2f13e
1 changed files with 8 additions and 13 deletions

View File

@ -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