[Answered ]-Haystack – 'SearchQuerySet' object has no attribute 'model'

2πŸ‘

The serializer expect pin objects but you are returning SearchResut objects

Try this

class PinSearchViewSet(viewsets.ReadOnlyModelViewSet):
    http_method_names = ['get']
    queryset = Pin.objects.all()
    serializer_class = PinSearchSerializer

    def get_queryset(self, *args, **kwargs):
        request = self.request
        queryset = EmptySearchQuerySet()
        if request.GET.get('q') is not None:
            query = request.GET.get('q')
            queryset = SearchQuerySet().filter(content=query).models(Pin)
        return [i.object for i in queryset]

I also specified pin model in the searchQuerySet

πŸ‘€Anoop

Leave a comment