python - 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
解决方案
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.
推荐阅读
- vb.net - 比较 ListViewItems 和 SelectedItems
- react-native - 如何使用参考连接
- java - Java,程序读取文件,输出是符号
- intellij-idea - IntelliJ Idea ctrl+shift+enter 在 Dart 和 Flutter 项目中工作奇怪
- python - Tensorflow BahdanauAttention - 层 memory_layer 需要 1 个输入,但它接收到 2 个输入张量
- swift - 快速 json 解析,没有 json 对象的标题
- php - Symfony 4 中的 Symfony 3 等价物
- sql - 将数学函数添加到 SQL 查询
- android - 如何在 Android 的 Spinner 的选择器中为 Vector 充气?
- jquery - 调用ajax url后在select中附加一个选项