[英]Binding list parameter with Django 1.3 ORM raw query
How to bind list in Django 1.3 ORM raw query? 如何在Django 1.3 ORM原始查询中绑定列表? Example what i want:
我想要的例子:
customers = [1, 2, 3]
# ....
customers_filter = "and products.customer_id in (%(customers)s)"
sql_params['customers'] = customers # <<< how to bind list?
# ....
cursor.execute(sql, sql_params)
Example, how i solve that problem 例子,我如何解决这个问题
total = {}
if customers:
sql_params.update({'customer_%s' % index: customer for index, customer in enumerate(customers)})
customers_filter = 'and t.customer_id in (%s)' % ', '.join(
'%%(customer_%s)s' % index for index, customer in enumerate(customers))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.