Skip to content

Instantly share code, notes, and snippets.

@adg29
Last active November 21, 2019 19:27
Show Gist options
  • Save adg29/f6a368e50f99c8d404129c916b359a47 to your computer and use it in GitHub Desktop.
Save adg29/f6a368e50f99c8d404129c916b359a47 to your computer and use it in GitHub Desktop.
Django pagination + React
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment