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
Post a Comment