mirror of https://github.com/django/django.git
Moved _get_model_tuple() to the base Operation class.
This allows field and special operations to use this logic.
This commit is contained in:
parent
1490611038
commit
2faeb21d2f
|
@ -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__,
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue