summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-04-25 15:02:25 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-04-25 15:02:25 +0000
commit05e4d51f0d1924efec47c39215d6baf682688fe7 (patch)
tree7d92c2387d614787f2f7565baaefc48c44b45f76 /django/db/models/sql
parentfcc3648b60c64b8242ddddb84d636e3a6248aee5 (diff)
queryset-refactor: Simplify the way filters are passed to the Query class.
This removes a lot of the complexity for handling exclude() calls and results in more efficient code. I feel a bit stupid for not having spotted this earlier. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7461 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/query.py19
1 files changed, 4 insertions, 15 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 864563ed8e..f431df332f 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -969,24 +969,11 @@ class Query(object):
# that's harmless.
self.promote_alias(table)
- entry = (alias, col, field, lookup_type, value)
- if negate and single_filter:
- # This case is when we're doing the Q2 filter in exclude(Q1, Q2).
- # It's different from exclude(Q1).exclude(Q2).
- for node in self.where.children:
- if getattr(node, 'negated', False):
- node.add(entry, connector)
- merged = True
- break
- else:
- self.where.add(entry, connector)
- merged = False
-
+ self.where.add((alias, col, field, lookup_type, value), connector)
if negate:
+ self.where.negate()
for alias in join_list:
self.promote_alias(alias)
- if not merged:
- self.where.negate()
if final > 1 and lookup_type != 'isnull':
for alias in join_list:
if self.alias_map[alias] == self.LOUTER:
@@ -1019,6 +1006,8 @@ class Query(object):
self.where.start_subtree(connector)
self.add_q(child)
self.where.end_subtree()
+ if q_object.negated:
+ self.where.children[-1].negate()
else:
self.add_filter(child, connector, q_object.negated,
single_filter=internal)