Im trying to pass several list to my URL through AJAX for filter purposes in my REST APIVIEW, but I couldn't get it right. i try to print using request.get function as well, but its now printing anything. below is my code :
Javascript :
//assume the rest of the array contain id like the list below
search_type_list = ['2', '4', '244, '42',]
a = "/api/dashboard/project_workorder_filter/{{selected_project.id}}/?search_type_list=" + search_type_value.join(',') + "/?parent_list=" + parent_value.join(',') + "/?status_list=" + status_value.join(',') + "/?task_list=" + task_value.join(',') + "/?user_list=" + user_value.join(',') + "/";
console.log(a)
content_workorder_filter_json = $.ajax({
type: "GET",
url: a,
dataType: "application/json",
async: false
}).responseText;
content_workorder_filter = JSON.parse(content_workorder_filter_json);
console.log(content_workorder_filter)
URl :
url(r'^api/dashboard/project_workorder_filter/(?P<project_id>\d+)/(?P<search_type_list>\w{0,1000})/(?P<parent_list>\w{0,1000})/(?P<status_list>\w{0,1000})/(?P<task_list>\w{0,1000})/(?P<user_list>\w{0,1000})/$', api.ProjectWorkorderFilterAPI.as_view(), name='project_workorder_filter'),
API.py
class ProjectWorkorderFilterAPI(APIView):
def get(self, request, project_id, search_type_list,format=None):
a = request.GET.get('search_type_list')
print(a)
model_object = WorkOrder.objects.filter(parent_project_content__project=project_id, search_type__id__in=[search_type_list], parent_project_content__parent__in=[parent_list], status__id__in=[status_list], task__id__in=[task_list], assign_to__id__in=[user_list] )
serializer = ProjectWorkorderSerializer(model_object, many=True)
return Response(serializer.data)