Django ORM查询问题:如何按列表过滤?

时间:2010-12-16 00:33:41

标签: django django-models

name = ['a','b']      # Hard coded list
customers = Customer.objects.filter(name=[]) # Want to filter by that list.

如何编写这样的查询?

1 个答案:

答案 0 :(得分:4)

Customer.objects.filter(name__in=['a', 'b', 'c'])

http://docs.djangoproject.com/en/dev/ref/models/querysets/#in