141๐
โ
You can override get_queryset
method for that purpose. As for query string parameters, you are right, request.data
holds POST data, you can get query string params through request.query_params
def get_queryset(self):
longitude = self.request.query_params.get('longitude')
latitude= self.request.query_params.get('latitude')
radius = self.request.query_params.get('radius')
location = Point(longitude, latitude)
queryset = Model.objects.filter(location__distance_lte=(location, D(m=distance))).distance(location).order_by('distance')
return queryset
๐คOzgur Akcali
4๐
I had the same problem, to solve it you can get parameters from url with self.request.parser_context.get('kwargs')
under the get_queryset
method.
๐คfarch
- [Django]-Django: reverse accessors for foreign keys clashing
- [Django]-Django filter many-to-many with contains
- [Django]-What is a "django backend"?
- [Django]-How to find out the request.session sessionid and use it as a variable in Django?
- [Django]-Django โ Annotate multiple fields from a Subquery
- [Django]-Django returning HTTP 301?
0๐
this actually worked for me .
using the self.request.query_params.get("lead_contact_id")
def get_queryset(self,*args,**kwargs):
# the lead id
lead_contact_id = self.request.query_params.get("lead_contact_id")
# this filter base on the lead id provided
feedback = Feedback.objects.filter(object_id=lead_contact_id)
return feedback
๐คCodertjay
- [Django]-Django model object with foreign key creation
- [Django]-Django logging of custom management commands
- [Django]-Django: Get model from string?
Source:stackexchange.com