Python Django随机排序列表
当我从数据库中获取“文章列表”时,如何对其进行排序Python Django随机排序列表,python,django,Python,Django,当我从数据库中获取“文章列表”时,如何对其进行排序 def article_theme(request, articleblock_id=2): return render_to_response('article_theme.html', {"ArticleBlock_name": ArticleBlock.objects.get(id=articleblock_id), 'articles_list': Articles.objects.filter (arti
def article_theme(request, articleblock_id=2):
return render_to_response('article_theme.html',
{"ArticleBlock_name": ArticleBlock.objects.get(id=articleblock_id),
'articles_list': Articles.objects.filter
(articles_articleblock_id=articleblock_id)})
这是:
Articles.objects.filter(articles_articleblock_id=articleblock_id).order_by('?')
它涉及从数据库中随机选取一行。它还链接到调查结果,说明为什么使用django文档中建议的order\u by('?')
效率低下。