[Django]-Django Rest Framework, passing parameters with GET request, classed based views

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

3๐Ÿ‘

use this simplest way you can get query param values:

request.GET.get("radius")
๐Ÿ‘คAnhad

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

Leave a comment