Django How to filter with multiple keywords -


i'm filtering data database based on "keyskill". eample i'm having following skills

  1. java
  2. python
  3. django
  4. html
  5. css

while filtering keyword "python" in search box datas related keyword fetched db. when search keyword "python,java" in search box, none of details fetched.

how filter data database using 2 keywords.

views.py

def search_result(request):      search = request.get['skills']     query = q(key_skills__icontains=search )     details = jobs.objects.filter(query)     return render_to_response('registration/searchresult.html', {'details': details}) 

models.py

class jobs(models.model):     title = models.charfield(max_length=30)     jobsummary = models.textfield()     jobdetails = models.textfield()     key_skills = models.charfield(max_length=30)     min_exp = models.integerfield(default=0)     max_exp = models.integerfield(default=0) 

for example in jobs table having 5 records having key skills (1.java 2.python 3.html ..etc..) while entering in search box "java" displayed details while entering in search box "java html" doesn't display so, need here display both java , html details

file.html

$(document).keypress(function(event){     var keycode = (event.keycode ? event.keycode : event.which);     if(keycode == '13'){         var keyword = $("#id_search_field").val();         if ( keyword == 'search') {             keyword = '';         }         if ((keyword != '')){             window.location.href = "/search_view/?key=" + keyword         }         window.location.href = "/search_view/?keyword=" + keyword            }     });      function keyword(){          var keyword = $("#id_search_field").val();         if ( keyword == '{% trans "search" %}') {             keyword = '';         }         if (keyword != ''){             window.location.href = "/search_view/?key=" + keyword         }         window.location.href = "/search_view/?keyword=" + keyword      }      <body>      <input type="text" name="place" placeholder="search" id="id_search_field"/></div>     <div class="searc">       <a href="#"><img src="/static/img/admin/search.png" alt="searchbox" onclick="keyword();"/></a>     </div>     {% in list %}       {{i.keyskill}}     {% endfor %}         </body> 

search_view(your views.py)

def search_view(request):      key = request.get.get('keyword')     if key not none:          key = key.lstrip()     if key :         list = dbtablename.objects.filter(q(keyskill__icontains = key)).order_by('-modified_at')     else:         list = dbtablename.objects.filter().order_by('-modified_at') 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -