复杂的'AND'Django查询

时间:2011-07-26 15:26:08

标签: python sql django django-queryset django-database

我正在尝试相当于这个SQL查询:

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

我无法弄明白。我试过以下但没有成功..

.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))

都会返回以下内容..并完全忽略我的括号......

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

1 个答案:

答案 0 :(得分:3)

逻辑运算符AND是关联的。 a&amp; b&amp; c ==(a&amp; b)&amp; c == a&amp; (b&amp; c)。不需要括号