The Python Oracle

Django Lazy Loading Pagination

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Mysterious Puzzle

--

Chapters
00:00 Django Lazy Loading Pagination
01:44 Accepted Answer Score 1
02:17 Thank you

--

Full question
https://stackoverflow.com/questions/3570...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#jquery #python #django #pagination #djangoendlesspagination

#avk47



ACCEPTED ANSWER

Score 1


Django Ajax would allow you to make Ajax calls to a Django view. You could wrap your results in a list then cache that. From there just pop the first 50 (or whatever size you want to set) when you initially render the view. Then pop your cache on the Ajax call.

Something like:

@django_ajax
def paginated_cache(request):
    more_results = [cache.get('your_results').pop() for result in range(50)]
    # turn this to json, wrap in dictionary and return

A more detailed instruction is on the django ajax page. This is for a smaller result size. For bigger results you may want to use something like a cursor though.