-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply filter to search results #25
Comments
Hi, So you are almost there in the example provided, but you should make sure that the queryset=self.list(request, *args, **kwargs).filter(eater=request.user.pk) and you should be good to go! |
@rhblind Thank you for your help, but maybe I am doing something wrong. self.list(request, *args, **kwargs) is a rest framework response of type: |
Ah, right =) Something like this should do it: class AppleViewSet(HaystackGenericAPIView):
# See http://drf-haystack.readthedocs.org/en/latest/basic_usage.html#views-py for how to set up the HaystackViewSet
def filter_queryset(self):
queryset = super(AppleViewSet, self).filter_queryset()
return queryset.filter(eater=self.request.user.pk) |
Ok, thank you. I modified your code and the final solution would be this code: class AppleViewSet(HaystackViewSet):
# See http://drf-haystack.readthedocs.org/en/latest/basic_usage.html#views-py for how to set up the HaystackViewSet
def filter_queryset(self, *args, **kwargs):
queryset = super(AppleViewSet, self).filter_queryset(self.get_queryset())
return queryset.filter(eater=self.request.user.pk) |
Yeah, sorry about the typo there. |
Is it possible to apply a filter on the results of the search specific for each request?
I would need something like this:
In this way I would display only the results which concern the creator of the request.
Thank you for the great project.
The text was updated successfully, but these errors were encountered: