Pass List of UUID to django endpoint url as param

I have this code

def report_pdf(request, queryset):
   if request.method == "GET":
       trans = Transaction.objects.filter(id__in=queryset)
    return something

path("pdf/<uuid:queryset>", views.report_pdf, name="get_pdf")

Now from my frontend react iam sending a get request to this endpoint with a list of UUID values. I cant find a way to access that list in my view coming from frontend.

Would appreciate any suggestions!

Answers: 2

Answered by Ahtisham, Jan. 13, 2022, 6:44 a.m.

You are sending list of uuid's from frontend but in your urls expects one uuid so that you need to change it like this:

path("pdf/", views.report_pdf, name="get_pdf")

def report_pdf(request):
    if request.method == "GET":
       uuid_list = request.GET.getlist("queryset[]")
       trans = Transaction.objects.filter(id__in=uuid_list)
    return something
Answered by Sukhpreet Singh, Jan. 13, 2022, 6:45 a.m.

I would suggest you pass the uuids as query params to the url as

../pdf?queryset=<uuids here>

then get the list in your view as

queryset = request.GET.get('queryset')

and then use queryset further in view.