mirror of
https://github.com/django/django.git
synced 2025-07-06 02:39:12 +00:00
queryset-refactor: Fixed a problem when adding certain additional filters to a queryset that has precisely one filter attached already.
Refs #6154. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6957 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
97091940b1
commit
519178154b
@ -792,6 +792,11 @@ class Query(object):
|
|||||||
q_object.add_to_query(self)
|
q_object.add_to_query(self)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if self.where and q_object.connector != AND and len(q_object) > 1:
|
||||||
|
self.where.start_subtree(AND)
|
||||||
|
subtree = True
|
||||||
|
else:
|
||||||
|
subtree = False
|
||||||
for child in q_object.children:
|
for child in q_object.children:
|
||||||
if isinstance(child, Node):
|
if isinstance(child, Node):
|
||||||
self.where.start_subtree(q_object.connector)
|
self.where.start_subtree(q_object.connector)
|
||||||
@ -799,6 +804,8 @@ class Query(object):
|
|||||||
self.where.end_subtree()
|
self.where.end_subtree()
|
||||||
else:
|
else:
|
||||||
self.add_filter(child, q_object.connector, q_object.negated)
|
self.add_filter(child, q_object.connector, q_object.negated)
|
||||||
|
if subtree:
|
||||||
|
self.where.end_subtree()
|
||||||
|
|
||||||
def setup_joins(self, names, opts, alias, dupe_multis):
|
def setup_joins(self, names, opts, alias, dupe_multis):
|
||||||
"""
|
"""
|
||||||
|
@ -87,8 +87,8 @@ class Node(object):
|
|||||||
def start_subtree(self, conn_type):
|
def start_subtree(self, conn_type):
|
||||||
"""
|
"""
|
||||||
Sets up internal state so that new nodes are added to a subtree of the
|
Sets up internal state so that new nodes are added to a subtree of the
|
||||||
current node. The conn_type is required so that the new subtree is
|
current node. The conn_type specifies how the sub-tree is joined to the
|
||||||
connected correctly to any existing nodes in the tree.
|
existing children.
|
||||||
"""
|
"""
|
||||||
if len(self.children) == 1:
|
if len(self.children) == 1:
|
||||||
self.connector = conn_type
|
self.connector = conn_type
|
||||||
|
@ -459,5 +459,12 @@ order_by() and filter() calls.
|
|||||||
>>> Item.objects.extra(select={'count': 'select count(*) from queries_item_tags where queries_item_tags.item_id = queries_item.id'}).filter(count=1)
|
>>> Item.objects.extra(select={'count': 'select count(*) from queries_item_tags where queries_item_tags.item_id = queries_item.id'}).filter(count=1)
|
||||||
[<Item: four>]
|
[<Item: four>]
|
||||||
|
|
||||||
|
Bug #6154
|
||||||
|
Multiple filter statements are joined using "AND" all the time.
|
||||||
|
|
||||||
|
>>> Author.objects.filter(id=a1.id).filter(Q(extra__note=n1)|Q(item__note=n3))
|
||||||
|
[<Author: a1>]
|
||||||
|
>>> Author.objects.filter(Q(extra__note=n1)|Q(item__note=n3)).filter(id=a1.id)
|
||||||
|
[<Author: a1>]
|
||||||
"""}
|
"""}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user