고장관리시스템--select 2단계 연결 조회

고장 관리 시스템을 쓸 때 메인 클래스-플랫폼에 따라 고장 검색을 하고select 2단계 연결 검색을 사용해야 한다
나 는 앞부분 의 기술 이 순박하여 수준 이 높은 동료 에게 가르침 을 청해서야 비로소 해결되었기 때문에, 나중에 다시 잊지 않도록 기록해 두었다
전면 html
                 
                          
                                $(document).ready(function() {       $('#se_program').change(function () {           se_program = $('#se_program').val();           data = {se_program: se_program};           $.ajax({               url:"/liandong/",               data:data,               type:'post',                   success: function(platform){                   $("#se_platform").empty();                   $("#se_platform").append("<option value='test_platform'>"+"请选择平台"+"</option>");                   $.each(platform,function(i){                   $("#se_platform").append("<option "+"value=\""+platform[i]+"\">"+platform[i]+"</option>")                      })               }           })       })})

django后端view

def search(request,page):
    """
      view,          ,         ,     ,     
    """
    check_Program=request.GET['Program']
    check_PlatForm=request.GET['PlatForm']
    check_Program=check_Program.encode("utf-8")
    check_PlatForm=check_PlatForm.encode("utf-8")
    if check_Program == 'test_program':
        return HttpResponseRedirect('/index/')
    if check_Program != 'test_program' and check_PlatForm=='test_platform':        
        ch_result = FaultReports.objects.filter(Program = check_Program)
        plat=FaultReports.objects.values_list('PlatForm',flat=True).filter(Program = check_Program)
        plat=set(plat)
        if ch_result:
            islogin=False
            page=gb001.try_int(page, 1)
            totalitems=FaultReports.objects.filter(Program = check_Program).count()
            pageInofobj=html.PageInfo(page,totalitems)
            pager=html.Search_Program_page('/search/',page,pageInofobj.TotalPage(),check_Program)
            all_data=FaultReports.objects.filter(Program = check_Program).order_by("-id")[pageInofobj.From():pageInofobj.To()]
            data=FaultReports.objects.values_list("Program",flat=True)
            data=set(data)
            try:
                islogin=request.session['islogin']
            except Exception,e:
                pass
            if islogin:
                name =request.session['username']
                return render_to_response('search.html',{'login_user':name,'pager':pager,'result':all_data,'search':data,'query':check_Program,'plat':plat})
            else:
                return HttpResponseRedirect('/login/')
    else:
        ch_result = FaultReports.objects.filter(Program = check_Program,PlatForm=check_PlatForm)
        plat=FaultReports.objects.values_list('PlatForm',flat=True).filter(Program = check_Program)
        plat=set(plat)
        print plat
        if ch_result:
            islogin=False
            page=gb001.try_int(page, 1)
            totalitems=FaultReports.objects.filter(Program = check_Program,PlatForm=check_PlatForm).count()
            pageInofobj=html.PageInfo(page,totalitems)
            pager=html.Search_Program_page('/search/',page,pageInofobj.TotalPage(),check_Program,check_PlatForm)
            all_data=FaultReports.objects.filter(Program = check_Program,PlatForm=check_PlatForm).order_by("-id")[pageInofobj.From():pageInofobj.To()]
            data=FaultReports.objects.values_list("Program",flat=True)
            data=set(data)
            try:
                islogin=request.session['islogin']
            except Exception,e:
                pass
            if islogin:
                name =request.session['username']
                return render_to_response('search.html',{'login_user':name,'pager':pager,'result':all_data,'search':data,'query':check_Program,'query_platform':check_PlatForm,'plat':plat})
            else:
                return HttpResponseRedirect('/login/')
def liandong(request):
    if request.method == 'POST':
        data=request.POST.get('se_program')
        print request.POST
        PlatFormList=[]
        contents = FaultReports.objects.filter(Program=data)
        for line in contents:
            if PlatFormList.count(line.PlatForm) ==0:
                PlatFormList.append(line.PlatForm)
        platform = PlatFormList
        #platform=set(platform)
        #print platform
        return HttpResponse(json.dumps(platform),content_type="application/json")

좋은 웹페이지 즐겨찾기