Moved _get_model_tuple() to the base Operation class.

This allows field and special operations to use this logic.
This commit is contained in:
Simon Charette 2017-11-24 03:05:40 -05:00 committed by Tim Graham
parent 1490611038
commit 2faeb21d2f
2 changed files with 9 additions and 9 deletions

View File

@ -1,4 +1,5 @@
from django.db import router
from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT
class Operation:
@ -124,6 +125,14 @@ class Operation:
return [self]
return False
def _get_model_tuple(self, remote_model, app_label, model_name):
if remote_model == RECURSIVE_RELATIONSHIP_CONSTANT:
return app_label, model_name.lower()
elif '.' in remote_model:
return tuple(remote_model.lower().split('.'))
else:
return app_label, remote_model.lower()
def __repr__(self):
return "<%s %s%s>" % (
self.__class__.__name__,

View File

@ -1,7 +1,6 @@
from django.db import models
from django.db.migrations.operations.base import Operation
from django.db.migrations.state import ModelState
from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT
from django.db.models.options import normalize_together
from django.utils.functional import cached_property
@ -279,14 +278,6 @@ class RenameModel(ModelOperation):
kwargs
)
def _get_model_tuple(self, remote_model, app_label, model_name):
if remote_model == RECURSIVE_RELATIONSHIP_CONSTANT:
return app_label, model_name.lower()
elif '.' in remote_model:
return tuple(remote_model.lower().split('.'))
else:
return app_label, remote_model.lower()
def state_forwards(self, app_label, state):
# Add a new model.
renamed_model = state.models[app_label, self.old_name_lower].clone()