django Paginator paginate without a serializer PaginateObject.object_list

def pagination(obj, request):
   max = request.GET.get(‘max’) if ‘max’ in request.GET else 1
   paginator = Paginator(obj, max)  # Show 25 contacts per page
   page = request.GET.get(‘page’)
   try:
       return paginator.page(page)
   except PageNotAnInteger:
       # If page is not an integer, deliver first page.
       return paginator.page(1)
   except EmptyPage:
       return “”

def folder_list(request):
   folders = UserFolder.objects.filter(creator=request.user).order_by(’-modified_date’)
   folders_dict = []
   for folder in folders:
       d = {}
       for k, v in folder.__dict__.items():
           d[k] = str(v)
       d[“creator__first_name”] = folder.creator.first_name
       folders_dict.append(d)
   folders = Common.pagination(folders_dict, request)
   folders = json.dumps(folders.object_list) #added .object_list
   return HttpResponse(folders)

Leave a Reply

Your email address will not be published.