Comments (5)
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)
from drf-haystack.
Hi,
Absolutely! But keep in mind that the QuerySet is a SearchQuerySet
not a regular one, so you need to have the field you want to filter on in the index.
So you are almost there in the example provided, but you should make sure that the eater
field in the index is holding the user id
(We can't index python models). Then make the filter like this:
queryset=self.list(request, *args, **kwargs).filter(eater=request.user.pk)
and you should be good to go!
from drf-haystack.
@rhblind Thank you for your help, but maybe I am doing something wrong.
I can't do what you suggested because
self.list(request, *args, **kwargs)
is a rest framework response of type: <class 'rest_framework.response.Response'>
, not a SearchQuerySet
.
from drf-haystack.
Ah, right =)
In that case I'd suggest to sublcass from the HaystackViewSet
where you can override ie. the filter_queryset()
method.
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)
from drf-haystack.
Yeah, sorry about the typo there.
That was what I meant :)
from drf-haystack.
Related Issues (20)
- Is there a way to include the score? HOT 1
- Logical Operator OR query with facets endpoint
- Looking for new maintainer HOT 11
- Serialize many to many field HOT 2
- Django 3.0 - no module named six HOT 2
- How would I do view-based caching for FacetMixin and HaystackViewSet views?
- Cannot install with Django 3 compatible version of Haystack HOT 1
- ImportError: cannot import name 'six' from 'django.utils'
- Highlighting fails with TypeError when highlighter_field value is None (while using HighlighterMixin) HOT 2
- how can i find search keyword
- How to specify a specific HAYStack_CONN?
- To sort the search results. HOT 1
- Even if there are more than 10,000 objects in the ListView, the number of objects will not be displayed in the results more than 10,000. HOT 2
- “python_requires” should be set with “>=3.6”, as drf-haystack 1.8.11 is not compatible with all Python versions.
- Please upgrade django version HOT 4
- Django 4.0 Incompatible HOT 1
- DRF 3.13 is not supported HOT 1
- Is this project still supported? HOT 7
- Loosen version requirements HOT 6
- Number of facets returned on elasticsearch are limited to 10 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drf-haystack.