From f1664a27345d09b91892cbaa46a7ab73bd62b219 Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Thu, 6 Oct 2016 11:02:48 +0100 Subject: [PATCH] Replaced '__' with LOOKUP_SEP constant. --- django/contrib/admin/checks.py | 3 ++- django/contrib/admin/utils.py | 2 +- django/core/management/commands/inspectdb.py | 9 +++++---- django/db/models/base.py | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py index d61ce723e36..1d802d2fbe7 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 6b5b05e3b2c..1e13d13d31b 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 31079c1a479..69721b1283a 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 e15ca006092..e7b3f3fd71d 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.