mirror of
				https://github.com/django/django.git
				synced 2025-10-31 16:07:30 +03:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									a78dd109e6
								
							
						
					
					
						commit
						c4aa26a983
					
				|  | @ -14,9 +14,10 @@ from django.core.exceptions import PermissionDenied, ValidationError | |||
| 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 | ||||
|  |  | |||
|  | @ -4,7 +4,7 @@ import datetime | |||
| 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 | ||||
|  |  | |||
|  | @ -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
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								django/db/models/constants.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,7 @@ | |||
| """ | ||||
| Constants used across the ORM in general. | ||||
| """ | ||||
| 
 | ||||
| # Separator used to split filter strings apart. | ||||
| LOOKUP_SEP = '__' | ||||
| 
 | ||||
|  | @ -8,6 +8,7 @@ import sys | |||
| 
 | ||||
| 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,9 +3,10 @@ from django.utils.six.moves import zip | |||
| 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 | ||||
|  |  | |||
|  | @ -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 @@ QUERY_TERMS = set([ | |||
| # 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). | ||||
|  |  | |||
|  | @ -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): | ||||
|  |  | |||
|  | @ -15,11 +15,12 @@ from django.utils.tree import Node | |||
| 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, | ||||
|  |  | |||
|  | @ -3,6 +3,7 @@ Query subclasses which provide extra functionality beyond simple data retrieval. | |||
| """ | ||||
| 
 | ||||
| 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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user