[Fixed]-Django – AttributeError at /prescription/ 'PrescriptionView' object has no attribute 'object_list'

1πŸ‘

βœ…

Once, I have used the following pattern while sending array of data:

var roles = data_selected();

$.ajax({
    type: 'POST',
    url: '/get_roles/',
    data: {'roles[]': roles},
   });
 });

And,in the django view, I

 def get_roles(request):
     roles = request.POST.getlist('roles[]')
     ....

Can you share you ajax call? I think the data might be messed while sending?

Handing post request :

def post(self, request, **kwargs):
      selected_ids = request.POST.getlist('selected[]')
      meds = self.get_queryset().filter(id__in=selected_ids)
      return render(request, self.template_name, {'meds': meds })

Leave a comment