在python / Django中使用过滤器中变量的正确方法是什么?从概念上讲,我想这样做:
whereconditionfield = 'rate_of_interest'
whereoperator = 'gte'
arri = 50.0
myqsfiltered=myqs.objects.filter(whereconditionfield__whereoperator=arri)
这样的事情可能吗?
答案 0 :(得分:5)
制作字典并unpack it into the keyword arguments:
kwargs = {whereconditionfield + "__" + whereoperator: arri}
myqs.objects.filter(**kwargs)