- simplifies pagination
- pass structure, next page, previous page, etc should be kept in mind
- JSON serialization must apply to everything
- use .values() for QuerySet, wrap result with list() e.g. for Paginator
from django.http.response import JsonResponse | |
def index(request): | |
influencers = Influencer.objects.all().values | |
paginator = Paginator(influencers, 16) | |
page = request.GET.get('page') | |
paged_listings = paginator.get_page(page) | |
user_list = UserList.objects.all().filter(user_id = request.user.id).values() | |
queryset = list(chain(paged_listings, user_list), paginator.count) | |
content = {'total_page_count': paginator.num_pages, 'data': queryset} | |
return JsonResponse(content) |