diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-04-28 04:29:06 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-04-28 04:29:06 +0000 |
| commit | e07a457c0054fa20dcbbf5bf41bc07191bdaa895 (patch) | |
| tree | d4456a807e2a8b66b66b1f6c0de6ad9df3b65734 /django/db/models/sql | |
| parent | a1e4b15f15d7807ddd35c0172b738a6e399235f6 (diff) | |
Fixed #7096 -- The simplifications in [7461] weren't complete. They broke
multi-component exclude() calls. Fixed that.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7493 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 59b2ebdd68..bfed984953 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -895,9 +895,15 @@ class Query(object): Add a single filter to the query. The 'filter_expr' is a pair: (filter_string, value). E.g. ('name__contains', 'fred') - If 'negate' is True, this is an exclude() filter. If 'trim' is True, we - automatically trim the final join group (used internally when - constructing nested queries). + If 'negate' is True, this is an exclude() filter. It's important to + note that this method does not negate anything in the where-clause + object when inserting the filter constraints. This is because negated + filters often require multiple calls to add_filter() and the negation + should only happen once. So the caller is responsible for this (the + caller will normally be add_q(), so that as an example). + + If 'trim' is True, we automatically trim the final join group (used + internally when constructing nested queries). If 'can_reuse' is a set, we are processing a component of a multi-component filter (e.g. filter(Q1, Q2)). In this case, 'can_reuse' @@ -1001,7 +1007,6 @@ class Query(object): 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 final > 1 and lookup_type != 'isnull': @@ -1039,12 +1044,12 @@ class Query(object): self.where.start_subtree(connector) self.add_q(child, used_aliases) self.where.end_subtree() - if q_object.negated: - self.where.children[-1].negate() else: self.add_filter(child, connector, q_object.negated, can_reuse=used_aliases) connector = q_object.connector + if q_object.negated: + self.where.negate() if subtree: self.where.end_subtree() |
