简体   繁体   English

如何在 Django 中过滤使用特定用户

[英]How to filtering in Django use specific user

I try to filtering django some specific user.我尝试过滤 django 一些特定用户。 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当我更改列表过滤器可以动态工作

You can use __in :您可以使用__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.注意:切勿使用 python 内置函数(例如: list )作为变量名。 It would be better to avoid the need for this by choosing a different variable name.最好通过选择不同的变量名来避免这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM