i need to add search functionality on django’s class based view

You can override the get_queryset method inside your ListView.

class BlogList(ListView):
    context_object_name = 'blogs'
    model = Blog
    template_name = 'App_Blog/blog_list.html'

    def get_queryset(self):
        search = self.request.GET.get('search', '') 
        blogs = Blog.objects.filter(blog_title__icontains=search)
        return blogs

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top