首页 > 解决方案 > How to filtering in Django use specific user

问题描述

I try to filtering django some specific user. I try with list but it not working. Do you have any solution.

list = ['bill gates','elon musk','aamir khan','larry page']
allPosts = Post.objects.filter(author=list)

When I change list filter can work dynamically

标签: pythondjangodjango-modelsdjango-views

解决方案


You can use __in:

my_list = ['bill gates','elon musk','aamir khan','larry page']
allPosts = Post.objects.filter(author__in=my_list)

Note: Never use python built in functions (Ex: list) as variable names. It would be better to avoid the need for this by choosing a different variable name.


推荐阅读