mirror of
https://github.com/django/django.git
synced 2025-07-06 02:39:12 +00:00
queryset-refactor: Changed the return type of an internal function.
Previous polymorphic return type was dumb. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7235 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
53634d4cdd
commit
d91479a287
@ -506,7 +506,7 @@ class ValuesQuerySet(QuerySet):
|
|||||||
# Default to all fields.
|
# Default to all fields.
|
||||||
field_names = [f.attname for f in self.model._meta.fields]
|
field_names = [f.attname for f in self.model._meta.fields]
|
||||||
|
|
||||||
self.query.add_fields(field_names)
|
self.query.add_fields(field_names, False)
|
||||||
self.query.default_cols = False
|
self.query.default_cols = False
|
||||||
self.field_names = field_names
|
self.field_names = field_names
|
||||||
|
|
||||||
|
@ -9,6 +9,10 @@ class EmptyResultSet(Exception):
|
|||||||
class FullResultSet(Exception):
|
class FullResultSet(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class JoinError(Exception):
|
||||||
|
def __init__(self, level):
|
||||||
|
self.level = level
|
||||||
|
|
||||||
class Empty(object):
|
class Empty(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ from django.db.models.sql.where import WhereNode, EverythingNode, AND, OR
|
|||||||
from django.db.models.sql.datastructures import Count
|
from django.db.models.sql.datastructures import Count
|
||||||
from django.db.models.fields import FieldDoesNotExist
|
from django.db.models.fields import FieldDoesNotExist
|
||||||
from django.core.exceptions import FieldError
|
from django.core.exceptions import FieldError
|
||||||
from datastructures import EmptyResultSet, Empty
|
from datastructures import EmptyResultSet, Empty, JoinError
|
||||||
from constants import *
|
from constants import *
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -507,10 +507,11 @@ class Query(object):
|
|||||||
pieces = name.split(LOOKUP_SEP)
|
pieces = name.split(LOOKUP_SEP)
|
||||||
if not alias:
|
if not alias:
|
||||||
alias = self.get_initial_alias()
|
alias = self.get_initial_alias()
|
||||||
result = self.setup_joins(pieces, opts, alias, False, False)
|
try:
|
||||||
if isinstance(result, int):
|
field, target, opts, joins = self.setup_joins(pieces, opts, alias,
|
||||||
|
False, False)
|
||||||
|
except JoinError:
|
||||||
raise FieldError("Cannot order by many-valued field: '%s'" % name)
|
raise FieldError("Cannot order by many-valued field: '%s'" % name)
|
||||||
field, target, opts, joins = result
|
|
||||||
alias = joins[-1][-1]
|
alias = joins[-1][-1]
|
||||||
col = target.column
|
col = target.column
|
||||||
|
|
||||||
@ -812,12 +813,12 @@ class Query(object):
|
|||||||
alias = self.get_initial_alias()
|
alias = self.get_initial_alias()
|
||||||
allow_many = trim or not negate
|
allow_many = trim or not negate
|
||||||
|
|
||||||
result = self.setup_joins(parts, opts, alias, (connector == AND),
|
try:
|
||||||
allow_many)
|
field, target, opts, join_list = self.setup_joins(parts, opts,
|
||||||
if isinstance(result, int):
|
alias, (connector == AND), allow_many)
|
||||||
self.split_exclude(filter_expr, LOOKUP_SEP.join(parts[:result]))
|
except JoinError, e:
|
||||||
|
self.split_exclude(filter_expr, LOOKUP_SEP.join(parts[:e.level]))
|
||||||
return
|
return
|
||||||
field, target, opts, join_list = result
|
|
||||||
if trim and len(join_list) > 1:
|
if trim and len(join_list) > 1:
|
||||||
extra = join_list[-1]
|
extra = join_list[-1]
|
||||||
join_list = join_list[:-1]
|
join_list = join_list[:-1]
|
||||||
@ -972,7 +973,7 @@ class Query(object):
|
|||||||
for join in joins:
|
for join in joins:
|
||||||
for alias in join:
|
for alias in join:
|
||||||
self.unref_alias(alias)
|
self.unref_alias(alias)
|
||||||
return pos + 1
|
raise JoinError(pos + 1)
|
||||||
if model:
|
if model:
|
||||||
# The field lives on a base class of the current model.
|
# The field lives on a base class of the current model.
|
||||||
alias_list = []
|
alias_list = []
|
||||||
@ -1128,17 +1129,20 @@ class Query(object):
|
|||||||
"""
|
"""
|
||||||
return not (self.low_mark or self.high_mark)
|
return not (self.low_mark or self.high_mark)
|
||||||
|
|
||||||
def add_fields(self, field_names):
|
def add_fields(self, field_names, allow_m2m=True):
|
||||||
"""
|
"""
|
||||||
Adds the given (model) fields to the select set. The field names are
|
Adds the given (model) fields to the select set. The field names are
|
||||||
added in the order specified.
|
added in the order specified.
|
||||||
"""
|
"""
|
||||||
alias = self.get_initial_alias()
|
alias = self.get_initial_alias()
|
||||||
opts = self.get_meta()
|
opts = self.get_meta()
|
||||||
|
try:
|
||||||
for name in field_names:
|
for name in field_names:
|
||||||
u1, target, u2, joins = self.setup_joins(name.split(LOOKUP_SEP),
|
u1, target, u2, joins = self.setup_joins(name.split(LOOKUP_SEP),
|
||||||
opts, alias, False, False, True)
|
opts, alias, False, allow_m2m, True)
|
||||||
self.select.append((joins[-1][-1], target.column))
|
self.select.append((joins[-1][-1], target.column))
|
||||||
|
except JoinError:
|
||||||
|
raise FieldError("Invalid field name: '%s'" % name)
|
||||||
|
|
||||||
def add_ordering(self, *ordering):
|
def add_ordering(self, *ordering):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user