How to filter a django queryset using an array on a field like SQL's “IN”?

十年热恋 提交于 2019-12-17 19:08:11

问题


I'd like to filter a django queryset using an array as a constraint on a field. AKA, my array, for example, a set of primary keys. I want to get only the objects that would be in that array, like the query in SQL would be

SELECT * from table where id in [1,3,4,5,6....];


回答1:


.filter(id__in=[1, 3, 4, 5, 6....])

Read more about it at Django docs.



来源:https://stackoverflow.com/questions/4016794/how-to-filter-a-django-queryset-using-an-array-on-a-field-like-sqls-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!