Thursday, October 30, 2014

Re: Django query in DetailView

Hello,

I _think_ your code looks right to me, though the query / or_query code is confusing. Print statements could be helpful there to be sure it's actually filtering something.

Does this code work?

def searchcandidate(request):
    query_string
= request.GET.get('q', '').strip()
    found_entries
= []
   
if query_string:
        found_entries
= CandidateToJob.objects.order_by('-candidate')
       
for term in query_string.split():  # or call your normalize_query() here
            q
= Q()
           
for field_name in ['candidate__user__first_name', 'candidate__user__last_name']:
                q
|= Q(**{"%s__icontains" % field_name: term})
            found_entries
.filter(q)
   
return render(request, 'dashboard/candidates_results.html', {'query_string': query_string, 'found_entries': found_entries})

Collin

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a5b873e8-6311-47e4-bf7c-382a97288c25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment