Reputation: 299
I'm getting an error while making the search functionality for my to-do list in Django.
I was following dennis ivy's tutorial, did the same thing what he did but I'm still getting the error.
My code:
class TaskList(LoginRequiredMixin, ListView):
model = Task
context_object_name = 'tasks'
# For each user
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['tasks'] = context['tasks'].filter(user= self.request.user)
context['count'] = context['tasks'].filter(complete = False).count()
search_input = self.request.GET.get('search-area') or ''
if search_input:
context['tasks'] = context['tasks'].filter(
title_icontains = search_input) # <= Here I get the error
context['search_input'] = search_input
return context
What is going wrong?
Upvotes: 0
Views: 1308
Reputation: 997
title_icontains acts like normal variable, whereas "__" double underscores are used for lookups, field relations etc.
context['tasks'] = context['tasks'].filter(
title__icontains = search_input)
Please refer : Making Queries- Django Doc
Upvotes: 1