python - Django filter to return results that start with the entered query -


i have problem pertaining results returned django queryset.

i have table classified on perform search operation based on input query q follows:

def search(request):     q = request.get['query']     result = classified.objects.filter(q(name__icontains=q) | q(category__icontains=q))     return render_to_response('search.html', {'result':result}, request) 

now example classified.name contains amity, ambulance, camden, cameroon. if type am query, according above filter it'll return 4 of mentioned entries.

my question here is, how return amity , ambulance results because that's requirements , plus makes search page more result oriented.

do you're doing use istartswith rather icontains

https://docs.djangoproject.com/en/dev/ref/models/querysets/#istartswith


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -