2

我得到了这种奇怪的行为

test_dict = {'productDue' : ['foo'],'releaseDue' : ['bar']}
for attr, value in test_dict.items() :
    print attr
    and_args = [(and_(getattr(my_table,attr).in_(value)))]

这给了我:

>>> print and_(*and_args)
"my_table"."releaseDue" IN (:releaseDue_1)

然后当我切换顺序时:

 test_dict = {'releaseDue' : ['bar'],'productDue' : ['foo']}
for attr, value in test_dict.items() :
    print attr
    and_args = [(and_(getattr(my_table,attr).in_(value)))]

我得到:

>>> print and_(*and_args)
"TDC"."releaseDue" IN (:releaseDue_1)

没看懂,想拥有"TDC"."releaseDue" IN (:releaseDue_1) AND "TDC"."productDue" IN (:productDue_1)

请帮忙

4

2 回答 2

1

谢谢,

我已经设法做到了:

and_args = [ (and_(getattr(my_table,attr).in_(value))) for attr, value in test_dict.items() ]
于 2013-07-16T14:40:56.087 回答
0

我不是 sqlalchemy 专家,但这是因为你在循环的每一遍都覆盖了 and_args 吗?

做类似的事情

test_dict = {'productDue' : ['foo'],'releaseDue' : ['bar']}
and_args = []
for attr, value in test_dict.items() :
    print attr
    and_args.append( and_(getattr(my_table,attr).in_(value) )
all = and_(*and_args)

做这个把戏?

于 2013-07-16T14:37:34.133 回答