如何有效的遍历django的QuerySet

如何有效的遍历django的QuerySet


小怪兽爱吃肉
浏览 753回答 1
1回答

斯蒂芬大帝

def get_employees(position, start, end):return employee.objects.filter(alert_time__lt=end,alert_time__gt=start).filter(position__in=position)@login_requireddef show(request):if not validate(request):return render_to_response('none.html',context_instance=RequestContext(request, 'msg':'params error'))position = request.REQUEST.get('position')time_range = request.REQUEST.get('time')start, end = time_range[0], time_range[1]num_per_page, page_num = get_num(request)all_employees = get_employees(position, start, end)# 根据当前页与每页展示的记录数,取到正确的记录employees = employees_events[(page_num-1)*num_per_page:page_num*num_per_page]return render_to_response('show_employees.html',context_instance=RequestContext(request,'employees': employees,'num_per_page': num_per_page,'page_num':page_num,'page_options' : [50, 100, 200]))
打开App,查看更多内容
随时随地看视频慕课网APP