Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand select two-level linkage query

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to understand the select two-level linkage query, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

When writing a fault management system, we need to use select two-level linkage query to search for faults according to the main class-platform.

Front-end html

Please select the main class {% for val in search%} {{val}} {% endfor%} Please select the platform search $(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 ("" + "Please select platform" + "); $.each (platform,function (I) {$(" # se_platform ") .append ("+ platform [I] +")}))

Django backend view

Def search (request,page): "" search view, receive the main class name from the front end, match the database to get the data, and return it to the 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 = 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") above is how to understand the select two-level linkage query The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report