Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Internal refactoring; moving LOOKUP_SEP up one level.

In an ideal world, nothing except django.db.models.query should have to
import stuff from django.models.sql.*. A few things were needing to get
hold of sql.constants.LOOKUP_SEP, so this commit moves it up to
django.db.models.constants.LOOKUP_SEP.

There are still a couple of places (admin) poking into sql.* to get
QUERY_TERMS, which is unfortunate, but a slightly different issue and
harder to adjust.
  • Loading branch information...
commit c4aa26a983c91b1ec015fe0552077847116dfab7 1 parent a78dd10
Malcolm Tredinnick malcolmt authored
3  django/contrib/admin/options.py
View
@@ -14,9 +14,10 @@
from django.core.paginator import Paginator
from django.core.urlresolvers import reverse
from django.db import models, transaction, router
+from django.db.models.constants import LOOKUP_SEP
from django.db.models.related import RelatedObject
from django.db.models.fields import BLANK_CHOICE_DASH, FieldDoesNotExist
-from django.db.models.sql.constants import LOOKUP_SEP, QUERY_TERMS
+from django.db.models.sql.constants import QUERY_TERMS
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.template.response import SimpleTemplateResponse, TemplateResponse
2  django/contrib/admin/util.py
View
@@ -4,7 +4,7 @@
import decimal
from django.db import models
-from django.db.models.sql.constants import LOOKUP_SEP
+from django.db.models.constants import LOOKUP_SEP
from django.db.models.deletion import Collector
from django.db.models.related import RelatedObject
from django.forms.forms import pretty_name
2  django/contrib/gis/db/models/sql/where.py
View
@@ -1,5 +1,5 @@
+from django.db.models.constants import LOOKUP_SEP
from django.db.models.fields import FieldDoesNotExist
-from django.db.models.sql.constants import LOOKUP_SEP
from django.db.models.sql.expressions import SQLEvaluator
from django.db.models.sql.where import Constraint, WhereNode
from django.contrib.gis.db.models.fields import GeometryField
7 django/db/models/constants.py
View
@@ -0,0 +1,7 @@
+"""
+Constants used across the ORM in general.
+"""
+
+# Separator used to split filter strings apart.
+LOOKUP_SEP = '__'
+
3  django/db/models/query.py
View
@@ -8,6 +8,7 @@
from django.core import exceptions
from django.db import connections, router, transaction, IntegrityError
+from django.db.models.constants import LOOKUP_SEP
from django.db.models.fields import AutoField
from django.db.models.query_utils import (Q, select_related_descend,
deferred_class_factory, InvalidQuery)
@@ -1613,8 +1614,6 @@ def prefetch_related_objects(result_cache, related_lookups):
Populates prefetched objects caches for a list of results
from a QuerySet
"""
- from django.db.models.sql.constants import LOOKUP_SEP
-
if len(result_cache) == 0:
return # nothing to do
3  django/db/models/sql/compiler.py
View
@@ -3,9 +3,10 @@
from django.core.exceptions import FieldError
from django.db import transaction
from django.db.backends.util import truncate_name
+from django.db.models.constants import LOOKUP_SEP
from django.db.models.query_utils import select_related_descend
from django.db.models.sql.constants import (SINGLE, MULTI, ORDER_DIR,
- LOOKUP_SEP, GET_ITERATOR_CHUNK_SIZE)
+ GET_ITERATOR_CHUNK_SIZE)
from django.db.models.sql.datastructures import EmptyResultSet
from django.db.models.sql.expressions import SQLEvaluator
from django.db.models.sql.query import get_order_dir, Query
11 django/db/models/sql/constants.py
View
@@ -1,7 +1,13 @@
+"""
+Constants specific to the SQL storage portion of the ORM.
+"""
+
from collections import namedtuple
import re
-# Valid query types (a set is used for speedy lookups).
+# Valid query types (a set is used for speedy lookups). These are (currently)
+# considered SQL-specific; other storage systems may choose to use different
+# lookup types.
QUERY_TERMS = set([
'exact', 'iexact', 'contains', 'icontains', 'gt', 'gte', 'lt', 'lte', 'in',
'startswith', 'istartswith', 'endswith', 'iendswith', 'range', 'year',
@@ -12,9 +18,6 @@
# Larger values are slightly faster at the expense of more storage space.
GET_ITERATOR_CHUNK_SIZE = 100
-# Separator used to split filter strings apart.
-LOOKUP_SEP = '__'
-
# Constants to make looking up tuple values clearer.
# Join lists (indexes into the tuples that are values in the alias_map
# dictionary in the Query class).
2  django/db/models/sql/expressions.py
View
@@ -1,6 +1,6 @@
from django.core.exceptions import FieldError
+from django.db.models.constants import LOOKUP_SEP
from django.db.models.fields import FieldDoesNotExist
-from django.db.models.sql.constants import LOOKUP_SEP
class SQLEvaluator(object):
def __init__(self, expression, query, allow_joins=True):
5 django/db/models/sql/query.py
View
@@ -15,11 +15,12 @@
from django.utils import six
from django.db import connections, DEFAULT_DB_ALIAS
from django.db.models import signals
+from django.db.models.constants import LOOKUP_SEP
from django.db.models.expressions import ExpressionNode
from django.db.models.fields import FieldDoesNotExist
from django.db.models.sql import aggregates as base_aggregates_module
-from django.db.models.sql.constants import (QUERY_TERMS, LOOKUP_SEP, ORDER_DIR,
- SINGLE, ORDER_PATTERN, JoinInfo)
+from django.db.models.sql.constants import (QUERY_TERMS, ORDER_DIR, SINGLE,
+ ORDER_PATTERN, JoinInfo)
from django.db.models.sql.datastructures import EmptyResultSet, Empty, MultiJoin
from django.db.models.sql.expressions import SQLEvaluator
from django.db.models.sql.where import (WhereNode, Constraint, EverythingNode,
1  django/db/models/sql/subqueries.py
View
@@ -3,6 +3,7 @@
"""
from django.core.exceptions import FieldError
+from django.db.models.constants import LOOKUP_SEP
from django.db.models.fields import DateField, FieldDoesNotExist
from django.db.models.sql.constants import *
from django.db.models.sql.datastructures import Date
Please sign in to comment.
Something went wrong with that request. Please try again.