root777

Untitled

Jul 9th, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // the function of searching by adding arguments of 'keywords' in url, how to pass another parameter, such as user's id in that url? They are not request_url = "user<int:pk>/course/list?keywords="+keywords or request_url = "request.user.pk/course/list?keywords="+keywords........
  2.  
  3. // views.py the function of searching
  4.         search_keywords = request.GET.get('keywords', '')
  5.         if search_keywords:
  6.             all_courses = all_courses.filter(Q(name__icontains=search_keywords) | Q(desc__icontains=search_keywords) | Q(
  7.                 detail__icontains=search_keywords))
  8.  
  9. // common.js function of searching
  10. function search_click(){
  11.     var type = $('#jsSelectOption').attr('data-value'),
  12.         keywords = $('#search_keywords').val(),
  13.         request_url = '';
  14.     if(keywords == ""){
  15.         return
  16.     }
  17.     if(type == "course"){
  18.         request_url = "/course/list?keywords="+keywords
  19.     }else if(type == "teacher"){
  20.         request_url = "/org/teacher/list?keywords="+keywords
  21.     }else if(type == "org"){
  22.         request_url = "/org/list?keywords="+keywords
  23.     }
  24.     window.location.href = request_url
  25. }
Advertisement
Add Comment
Please, Sign In to add comment