1

Here comes another problem from the Django-Haystack custom queryset.

How can I create a Django Rest Framework List View (or whatever view) that uses Django-Haystack's custom queryset attribute as a queryset?

The difference is basically that where the regular queryset attribute contains regular objects, the Django-Haystack's custom queryset contains a dictionary with an 'object' property that returns the object.

Queryset:
[<ModelInstance_1>, <ModelInstance_2>]

SearchQuerySet
[{object: <ModelInstance_1>}, {object: <ModelInstance_2>}]

I have searched before posting, and found a couple of answers but they are using outdated versions which work very differently than the way it works now.

I am currently using something like this:

class SearchProjectsView(generics.ListAPIView):
serializer_class = ArchiveProjectSerializer
model = Project

def get_queryset(self):
    queryset = []
    for result in SearchQuerySet().models(Project).filter(content=Clean(self.request.QUERY_PARAMS.get('q', ''))):
        queryset.append(result.object)
    return queryset

But as soon as I extend this with pagination or any other minor issue it will become a problem..

1 Answer 1

2

Sorry to bump old thread, but I've written a library for this. Check out drf-haystack :) https://github.com/inonit/drf-haystack

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.