简体   繁体   English

django中具有limit和order_by的数据库查询

[英]database query with limit and order_by in django

i want to display database in table using limit 5 and order_by, whenever i use this query than it show the detail in the table with limit 5 but the list is not in ascending order. 我想使用限制5和order_by在表中显示数据库,每当我使用此查询时,它就会在限制5的表中显示详细信息,但列表未按升序排列。

views.py :- views.py:-

def applicationvalues(request):
    gettablevalues = applicationform.objects.all().order_by('-id')[:5]
    getinterviewvalues = interview.objects.all()
    getjobvalues = jobs.objects.all()
    return render_to_response('registration/tableview.html', {'gettablevalues': gettablevalues, 'getinterviewvalues': getinterviewvalues, 'getjobvalues': getjobvalues})
gettablevalues = applicationform.objects.all().order_by('-id')[:5]

putting - before the field sorts it in descending order. 放置-在字段按降序排序之前。 I would also have thought that it would be sorted by id in ascending order by default (unless you've overridden that on the model). 我也曾想过,默认情况下它将按id升序排序(除非您在模型上覆盖了它)。

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

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