articles/views.py
def search(self, request):
        """
        Returns the top 10 search results matching,
        the title of the blog
        """
        query = request.GET.get('query', None)
        article_set = Article.objects.filter(is_published=True)

        # If query is provided search for it or return everything
        if query:
            article_set = article_set.filter(title__icontains=query)[:10]

        serializer = ArticleListSerializer(article_set, many=True)

        if serializer.data:
            return Response(serializer.data)
        else:
            return Response({}, status=404)

        Returns the top 10 search results matching,
        the title of the blog
        
Returns the top 10 search results matching,
the title of the blog
Returns the top 10 search results matching the title of the blog
def search(self, request):
        query = request.GET.get('query', None)
        article_set = Article.objects.filter(is_published=True)
        if query:
            article_set = article_set.filter(title__icontains=query)[:10]
        serializer = ArticleListSerializer(article_set, many=True)
        if serializer.data:
            return Response(serializer.data)
        else:
            return Response({}, status=404)
def search ( self , request ) : query = request . GET . get ( 'query' , None ) article_set = Article . objects . filter ( is_published = True ) if query : article_set = article_set . filter ( title__icontains = query ) [ : 10 ] serializer = ArticleListSerializer ( article_set , many = True ) if serializer . data : return Response ( serializer . data ) else : return Response ( { } , status = 404 )
Returns the top 10 search results matching,
the title of the blog
Returns the top 10 search results matching the title of the blog
"""
        Returns the top 10 search results matching,
        the title of the blog
        """ # If query is provided search for it or return everything
self
request