name = ['a','b'] # Hard coded list
customers = Customer.objects.filter(name=[]) # Want to filter by that list.
如何编写这样的查询?
答案 0 :(得分:4)
Customer.objects.filter(name__in=['a', 'b', 'c'])
http://docs.djangoproject.com/en/dev/ref/models/querysets/#in