2 Various data structures used in query construction.
4 Factored out from django.db.models.query so that they can also be used by other
5 modules without getting into circular import difficulties.
8 from copy
import deepcopy
10 from django
.utils
import tree
12 class QueryWrapper(object):
14 A type that indicates the contents are an SQL fragment and the associate
15 parameters. Can be used to pass opaque data to a where-clause, for example.
17 def __init__(self
, sql
, params
):
18 self
.data
= sql
, params
22 Encapsulates filters as objects that can then be combined logically (using
30 def __init__(self
, *args
, **kwargs
):
31 super(Q
, self
).__init
__(children
=list(args
) + kwargs
.items())
33 def _combine(self
, other
, conn
):
34 if not isinstance(other
, Q
):
35 raise TypeError(other
)
40 def __or__(self
, other
):
41 return self
._combine
(other
, self
.OR
)
43 def __and__(self
, other
):
44 return self
._combine
(other
, self
.AND
)