Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
django如何在listview url中混合order__by和get?_Django - Fatal编程技术网

django如何在listview url中混合order__by和get?

django如何在listview url中混合order__by和get?,django,Django,所以我想创造: 选择*from Post where Post.is_selected=按创建日期确定的真实订单 我希望这发生在url.py中(也就是说,不必定义任何内容,只需将其粘贴在ListView参数中) 我该怎么做 我目前有: url(r'^$',ListView.as_view( queryset=Post.objects.get(is_chosen = True).order_by('-pub_date')[:20], context_object_name='lat

所以我想创造:

选择*from Post where Post.is_selected=按创建日期确定的真实订单

我希望这发生在url.py中(也就是说,不必定义任何内容,只需将其粘贴在ListView参数中)

我该怎么做

我目前有:

url(r'^$',ListView.as_view(
    queryset=Post.objects.get(is_chosen = True).order_by('-pub_date')[:20],
    context_object_name='latest_post_list',
    template_name='posts/index.html')),
但是这有一个错误-我不能在“get”的返回对象上调用order_by这是有意义的,但是我如何做我想要的呢

如果在url定义中无法执行,我愿意从已定义的函数调用该命令

更新:啊,我是个白痴

“get”只返回一个项目,因此“order_by”当然不起作用。我现在用过滤器代替

比如说,改用
.filter()