django filter from two fields with single input -


i'm having table fields skills , title. want filter these fields single input.

models.py class job(model.model):      title = models.charfield(max_length=30)      skills = models.charfield(max_length=30)  search.html <form> <input type="text" name="skills" /> <input type="submit" /> </form>  views.py jobs.objects.filter(skills__icontains=request.get['skills'],title__icontains=request.get['skills']) 

while trying code can't output. need output when entering title or skills in input box matches both skills , title. should single input.some 1 me..

your code searches jobs both title , skills contain request.get['skills']. search jobs title or skills (or both) contain request.get['skills'], have use q objects:

from django.db.models import q ... search = request.get['skills']         #     skills contain search  or  title contains search query = q(skills__icontains=search ) | q(title__icontains=search ) job.objects.filter(query) 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

php - HTTP_REFERER woes: How can I allow access to a specific page, only when a visitor has visited another specific page beforehand? -

java Extracting Zip file -