现在我有了这段代码:
attitude = request.REQUEST['attitude']
if attitude == 'want':
qs = qs.filter(attitudes__want=True)
elif attitude == 'like':
qs = qs.filter(attitudes__like=True)
elif attitude == 'hate':
qs = qs.filter(attitudes__hate=True)
elif attitude == 'seen':
qs = qs.filter(attitudes__seen=True)
最好动态定义“attitudes__xxxx”的名称。有没有办法做到这一点?
谢谢!
答案 0 :(得分:7)
是
qs.filter( **{ 'attitudes__%s'%arg:True } )