[Fixed]-Django searching function issue

1👍

You have a wrong signature of the get_queryset method. It does not accept request as a second parameter. You can access request from a self variable.

class IndexView(ListView):
    template_name = 'games/list.html'
    context_object_name = 'all_games'
    model = Games

    def get_queryset(self):  # no second parameter
        query = self.request.GET.get("q")  # get request here
        queryset_list = Games.objects.all()  # initialize queryset
        if query:
            # apply filter to the queryset_list
            queryset_list = queryset_list.filter(
                Q(name__icontains=query) |
                Q(platform__icontains=query) |
                Q(genre__icontains=query) |
                Q(language__icontains=query)
            ).distinct()
        return queryset_list

You can find more information in django documentation of get_queryset method

👤taras

Leave a comment