Querysets are now lest restrictive when querying duplicate fields (#332, #333)

This commit is contained in:
Ross Lawley
2013-06-04 10:46:38 +00:00
parent 985bfd22de
commit ee725354db
3 changed files with 28 additions and 8 deletions

View File

@@ -26,6 +26,7 @@ class QNodeVisitor(object):
class DuplicateQueryConditionsError(InvalidQueryError):
pass
class SimplificationVisitor(QNodeVisitor):
"""Simplifies query trees by combinging unnecessary 'and' connection nodes
into a single Q-object.
@@ -39,6 +40,7 @@ class SimplificationVisitor(QNodeVisitor):
try:
return Q(**self._query_conjunction(queries))
except DuplicateQueryConditionsError:
# Cannot be simplified
pass
return combination
@@ -127,8 +129,7 @@ class QCombination(QNode):
# If the child is a combination of the same type, we can merge its
# children directly into this combinations children
if isinstance(node, QCombination) and node.operation == operation:
# self.children += node.children
self.children.append(node)
self.children += node.children
else:
self.children.append(node)