Write fault management system, according to the main class-platform for fault search, need to use the select two-level linkage query
My front-end technology pure rookie, asked a high level of colleagues to take care of, so record down, lest later forget
Front-end HTML
<form id= "tab" class= "Form-inline" role= "form" action= '/search/' method= ' GET ' style= "float:right;margin-top:-48px;margin-right:0px;" > <!--<div class= "panel-heading" >--> <div class= "Form-group" > <select class= "Form-control" name= "program" id= "Se_program" > <option value= "Test_program" > Please select Main class </option> {% for val in search %} <option value= "{{ val }}" { % if val == query %}selected{% endif %}>{{ val }}</option > {% endfor %} </select> < select class= "Form-control" name= "PlatForm" id= "Se_platform" > <option value= "Test_platform" > Please select Platform </option> </select> </div> <button class= "Btn btn-primary" type= "Submit" > <i class= "Fa fa-save" ></i>search</button> <!--</div>--> </form><script type= "Application/javascript" > $ (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 ' >" + "Please select platform" + "</ Option> "); &nBsp; $.each (Platform, function (i) { $ ("#se_platform"). Append ("<option " + "value=\" "+platform[i]+" \ ">" +platform[i]+ "</ Option> ") }) } }) }) </script>
Django back-end view
Def search (request,page): "" " search view, receive the main class name from the front end, match the database to get the data, Back to front end, custom paging "" " 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 =&Nbsp;check_program) plat=set (plat) if ch_result: islogin=false page=gb001.try_int ( PAGE,&NBSP;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 ():p ageinofobj.to ()] &nBsp; 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 ':p ager, ' result ' : All_data, ' Search ':d atA, ' query ': Check_program, ' plat ':p lat}) 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) &nbSp; 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 ():p ageinofobj.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 ':p ager, ' result ': all_data, ' Search ':d ata, ' query ': Check_program, ' query_platform ': check_platform, ' plat ':p lat}) else: return httpresponseredirect ('/ Login/')
Fault management system--select two-level linkage query