summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2016-10-06 11:02:48 +0100
committerTim Graham <timograham@gmail.com>2016-10-11 11:14:06 -0400
commitf1664a27345d09b91892cbaa46a7ab73bd62b219 (patch)
tree25948570cdd9abd1ae4ebd1cadec8b3e8a65542b
parenta346a88d46e420d21374377c2027f78c8989503b (diff)
Replaced '__' with LOOKUP_SEP constant.
-rw-r--r--django/contrib/admin/checks.py3
-rw-r--r--django/contrib/admin/utils.py2
-rw-r--r--django/core/management/commands/inspectdb.py9
-rw-r--r--django/db/models/base.py2
4 files changed, 9 insertions, 7 deletions
diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
index d61ce723e3..1d802d2fbe 100644
--- a/django/contrib/admin/checks.py
+++ b/django/contrib/admin/checks.py
@@ -11,6 +11,7 @@ from django.contrib.admin.utils import (
from django.core import checks
from django.core.exceptions import FieldDoesNotExist
from django.db import models
+from django.db.models.constants import LOOKUP_SEP
from django.forms.models import (
BaseModelForm, BaseModelFormSet, _get_foreign_key,
)
@@ -458,7 +459,7 @@ class BaseModelAdminChecks(object):
]
elif field_name == '?':
return []
- elif '__' in field_name:
+ elif LOOKUP_SEP in field_name:
# Skip ordering in the format field1__field2 (FIXME: checking
# this format would be nice, but it's a little fiddly).
return []
diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py
index 6b5b05e3b2..1e13d13d31 100644
--- a/django/contrib/admin/utils.py
+++ b/django/contrib/admin/utils.py
@@ -30,7 +30,7 @@ def lookup_needs_distinct(opts, lookup_path):
"""
Returns True if 'distinct()' should be used to query the given lookup path.
"""
- lookup_fields = lookup_path.split('__')
+ lookup_fields = lookup_path.split(LOOKUP_SEP)
# Remove the last item of the lookup path if it is a query term
if lookup_fields[-1] in QUERY_TERMS:
lookup_fields = lookup_fields[:-1]
diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index 31079c1a47..69721b1283 100644
--- a/django/core/management/commands/inspectdb.py
+++ b/django/core/management/commands/inspectdb.py
@@ -6,6 +6,7 @@ from collections import OrderedDict
from django.core.management.base import BaseCommand, CommandError
from django.db import DEFAULT_DB_ALIAS, connections
+from django.db.models.constants import LOOKUP_SEP
from django.utils.encoding import force_text
@@ -189,10 +190,10 @@ class Command(BaseCommand):
if num_repl > 0:
field_notes.append('Field renamed to remove unsuitable characters.')
- if new_name.find('__') >= 0:
- while new_name.find('__') >= 0:
- new_name = new_name.replace('__', '_')
- if col_name.lower().find('__') >= 0:
+ if new_name.find(LOOKUP_SEP) >= 0:
+ while new_name.find(LOOKUP_SEP) >= 0:
+ new_name = new_name.replace(LOOKUP_SEP, '_')
+ if col_name.lower().find(LOOKUP_SEP) >= 0:
# Only add the comment if the double underscore was in the original name
field_notes.append("Field renamed because it contained more than one '_' in a row.")
diff --git a/django/db/models/base.py b/django/db/models/base.py
index e15ca00609..e7b3f3fd71 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -1617,7 +1617,7 @@ class Model(six.with_metaclass(ModelBase)):
# Skip ordering in the format field1__field2 (FIXME: checking
# this format would be nice, but it's a little fiddly).
- fields = (f for f in fields if '__' not in f)
+ fields = (f for f in fields if LOOKUP_SEP not in f)
# Skip ordering on pk. This is always a valid order_by field
# but is an alias and therefore won't be found by opts.get_field.