Formatting fix for [3248]

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3250 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-07-01 03:21:32 +00:00
parent 31eb140b5a
commit ec23edfc7f
1 changed files with 21 additions and 24 deletions

View File

@ -13,15 +13,12 @@ if not hasattr(__builtins__, 'set'):
# The string constant used to separate query parts # The string constant used to separate query parts
LOOKUP_SEPARATOR = '__' LOOKUP_SEPARATOR = '__'
# The list of valid query types # The list of valid query types
QUERY_TERMS=( QUERY_TERMS = (
'exact', 'iexact', 'exact', 'iexact', 'contains', 'icontains',
'contains', 'icontains', 'gt', 'gte', 'lt', 'lte', 'in',
'gt', 'gte', 'lt', 'lte',
'in',
'startswith', 'istartswith', 'endswith', 'iendswith', 'startswith', 'istartswith', 'endswith', 'iendswith',
'range', 'year', 'month', 'day', 'range', 'year', 'month', 'day', 'isnull',
'isnull'
) )
# Size of each "chunk" for get_iterator calls. # Size of each "chunk" for get_iterator calls.
@ -216,7 +213,7 @@ class QuerySet(object):
raise self.model.DoesNotExist, "%s matching query does not exist." % self.model._meta.object_name raise self.model.DoesNotExist, "%s matching query does not exist." % self.model._meta.object_name
assert len(obj_list) == 1, "get() returned more than one %s -- it returned %s! Lookup parameters were %s" % (self.model._meta.object_name, len(obj_list), kwargs) assert len(obj_list) == 1, "get() returned more than one %s -- it returned %s! Lookup parameters were %s" % (self.model._meta.object_name, len(obj_list), kwargs)
return obj_list[0] return obj_list[0]
def create(self, **kwargs): def create(self, **kwargs):
""" """
Create a new object with the given kwargs, saving it to the database Create a new object with the given kwargs, saving it to the database
@ -723,7 +720,7 @@ def parse_lookup(kwarg_items, opts):
# a dummy name of None, which we will replace when # a dummy name of None, which we will replace when
# we know which table column to grab as the primary key. # we know which table column to grab as the primary key.
# 2) If there is only one part, or the last part is not a query # 2) If there is only one part, or the last part is not a query
# term, assume that the query is an __exact # term, assume that the query is an __exact
clause = path.pop() clause = path.pop()
if clause == 'pk': if clause == 'pk':
clause = 'exact' clause = 'exact'
@ -857,10 +854,10 @@ def lookup_inner(path, clause, value, opts, table, column):
# There are elements left in the path. More joins are required. # There are elements left in the path. More joins are required.
if len(path) == 1 and path[0] in (new_opts.pk.name, None) \ if len(path) == 1 and path[0] in (new_opts.pk.name, None) \
and clause in ('exact', 'isnull') and not join_required: and clause in ('exact', 'isnull') and not join_required:
# If the next and final name query is for a primary key, # If the next and final name query is for a primary key,
# and the search is for isnull/exact, then the current # and the search is for isnull/exact, then the current
# (for N-1) or intermediate (for N-N) table can be used # (for N-1) or intermediate (for N-N) table can be used
# for the search - no need to join an extra table just # for the search - no need to join an extra table just
# to check the primary key. # to check the primary key.
new_table = current_table new_table = current_table
else: else:
@ -887,15 +884,15 @@ def lookup_inner(path, clause, value, opts, table, column):
where.extend(where2) where.extend(where2)
params.extend(params2) params.extend(params2)
else: else:
# No elements left in path. Current element is the element on which # No elements left in path. Current element is the element on which
# the search is being performed. # the search is being performed.
if join_required: if join_required:
# Last query term is a RelatedObject # Last query term is a RelatedObject
if field.field.rel.multiple: if field.field.rel.multiple:
# RelatedObject is from a 1-N relation. # RelatedObject is from a 1-N relation.
# Join is required; query operates on joined table. # Join is required; query operates on joined table.
column = new_opts.pk.name column = new_opts.pk.name
joins[backend.quote_name(new_table)] = ( joins[backend.quote_name(new_table)] = (
backend.quote_name(new_opts.db_table), backend.quote_name(new_opts.db_table),
"INNER JOIN", "INNER JOIN",
@ -907,16 +904,16 @@ def lookup_inner(path, clause, value, opts, table, column):
) )
current_table = new_table current_table = new_table
else: else:
# RelatedObject is from a 1-1 relation, # RelatedObject is from a 1-1 relation,
# No need to join; get the pk value from the related object, # No need to join; get the pk value from the related object,
# and compare using that. # and compare using that.
column = current_opts.pk.name column = current_opts.pk.name
elif intermediate_table: elif intermediate_table:
# Last query term is a related object from an N-N relation. # Last query term is a related object from an N-N relation.
# Join from intermediate table is sufficient. # Join from intermediate table is sufficient.
column = join_column column = join_column
elif name == current_opts.pk.name and clause in ('exact', 'isnull') and current_column: elif name == current_opts.pk.name and clause in ('exact', 'isnull') and current_column:
# Last query term is for a primary key. If previous iterations # Last query term is for a primary key. If previous iterations
# introduced a current/intermediate table that can be used to # introduced a current/intermediate table that can be used to
# optimize the query, then use that table and column name. # optimize the query, then use that table and column name.
column = current_column column = current_column