Chris
Chris

Reputation: 703

Complex 'AND' Django Queries

I'm trying to do the equivalent of this SQL query:

"SELECT * FROM something WHERE ((something >= something AND something <= something) AND(something >= something AND something <= something))"

And I can't quite figure it out. I've tried the following with no success..

.filter(( Q(something__gte=something) & Q(something__lte=something)) & ( Q(something__gte=something) & Q(something__lte=something)))

.filter( Q(something__gte=something,something__lte=something) & Q(something__gte=something,something__lte=something))

both returns the following.. and completely ignores my brackets...

WHERE (`something`.`something` >= something  AND `something`.`something` <= -something  AND `something`.`something` >= something  AND `something`.`something` <= something )

Upvotes: 0

Views: 123

Answers (1)

SingleNegationElimination
SingleNegationElimination

Reputation: 156278

the logical operator AND is associative. a & b & c == (a & b) & c == a & (b & c). No parentheses are needed

Upvotes: 3

Related Questions