I am trying to return the elements of the table professionals
and the next page, both data in a JSON. The problem arises when I see the JSON that is returned: my professionals model is a string, not an array of objects. Here I leave my code:
if request.is_ajax():
professionals = Professionals.objects.defer('id_card')
paginator = Paginator(professionals, 2)
page = request.GET.get('page')
try:
professionals = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
professionals = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
professionals = paginator.page(paginator.num_pages)
data_response = {}
data_response['professionals'] = serializers.serialize("json", professionals)
data_response['next_page'] = professionals.next_page_number() if (professionals.has_next()) else -1
return HttpResponse(json.dumps(data_response), content_type = "application/json")
return HttpResponseNotFound('<h1>Page not found</h1>')
I would like it to be returned as currentProfessional
which I did by hand to show.
Thank you very much