Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.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中给出限制?_Django - Fatal编程技术网

我怎样才能在django中给出限制?

我怎样才能在django中给出限制?,django,Django,我正在做一个项目,想使用limit来获取数据如果有任何函数或任何方式可以限制我的获取数据,我如何使用limit 我预计(2019,12,27)(2019,6,30)的输出将是(2019,12,27),但它将获取所有记录 def maintenancefunction(request): #maintenance page function if 'user' not in request.session: return redirect('/login') els

我正在做一个项目,想使用limit来获取数据如果有任何函数或任何方式可以限制我的获取数据,我如何使用limit

我预计(2019,12,27)(2019,6,30)的输出将是(2019,12,27),但它将获取所有记录

def maintenancefunction(request): #maintenance page function
    if 'user' not in request.session:
        return redirect('/login')
    else:
        if request.session.has_key('user'):
            abc=request.session['user']

            today = date(2019,1,1)                        # today= date.today.().strftime('%d/%m/%Y')
            next_date=today.strftime('%Y-%m-%d')
            lastdate= today + timedelta(days=180)
            new_date= lastdate.strftime('%Y-%m-%d')

            duedate=maintanance_table.objects.values_list('maintanance_todate').filter(user_email=abc).order_by('maintanance_todate').reverse()
            #         # newduedate=duedate.strftime('%Y-%m-%d')
            print("DueDate:",duedate)
            checkstatus=maintanance_table.objects.filter(user_email=abc).filter(maintanance_status="PAID").order_by('maintanance_todate').reverse()
            if checkstatus:

                lastdate = lastdate + timedelta(days=180)
                new_date = lastdate.strftime('%Y-%m-%d')

            else:
                lastdate=lastdate
                new_date= lastdate.strftime('%Y-%m-%d')
                return render(request,"maintenance.html", {'abc':abc,'new_date':new_date})
        else:
            return render(request,"login.html")     
    return render(request,"maintenance.html")

您可以在查询末尾添加范围,如
[1-10]
,如果需要第一条记录,则只需在查询末尾添加
[0]
。如果需要特定记录,请将其编号放在查询的末尾,如
[5]
[3]

duedate=maintanance_table.objects.values_list('maintanance_todate').filter(user_email=abc).order_by('maintanance_todate').reverse()[1-10]

checkstatus=maintanance_table.objects.filter(user_email=abc).filter(maintanance_status="PAID").order_by('maintanance_todate').reverse()[1-10]