From 14f144e7ea6d80398cf3e3c38454126356baff21 Mon Sep 17 00:00:00 2001 From: Bishwas Bhandari Date: Sat, 9 Mar 2024 10:55:26 +0545 Subject: [PATCH] cursor pagination betterified added --- djapy/core/__pycache__/dec.cpython-311.pyc | Bin 12745 -> 12797 bytes djapy/core/dec.py | 1 + djapy/core/pagination/cursor_pagination.py | 20 ++++++++++---------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/djapy/core/__pycache__/dec.cpython-311.pyc b/djapy/core/__pycache__/dec.cpython-311.pyc index c42382d1827383214eaab0b649da3e657b5e13d2..6d2f7fb6e2899d9285ee96fd494f3e2eabc056c9 100644 GIT binary patch delta 510 zcmX?^{5P3*IWI340}zzHew}K#k@u(sumN?m$IBwg!PzCYlRro+GRjXDlCflTm|QO;DaqN%nGRB~2veWO-pL8# zZ?2PJ;$l>q+^DvQwV)_7uVk{K`Z~4=KxIV}Ctp?1VvL;ZpmCX*n^R@7nC3*0uN(}# zLKlRTF7hZ};ZeT8qx?WlY4aLQVMfNOlMiSam<2Mj%6?!Vjr^LnSxtK-BV+I63p!nl zlO{*&Dlx9#T&FvkIUt>pQS<`?h@4OXp>N0-Zg9C^>37A%|Dufl2WF7m15wEjtYD>V z48r0Qil=CPU7ef?d65|JMFb8Y{#C$Yz I@(M#m07sX8YybcN delta 511 zcmeyHd@`ALIWI340}$+a`8t(%BkxfO#x0vKOL#FdrcRcVIwg|A(a9b!0#X11o!mg4 z=wvBrX=@#b2#8E)SjNo2uo{RV0H{VB&gQ6K>|}_Sfb-eoB_RF6llT$S=GjnnBO}5sY$ohecL0)B limit + queryset_with_cursor = queryset.filter(id__gt=cursor) - # After processing the queryset, the cursor will be set to the id of the last item - cursor = str(queryset_subset.last().id) if has_next else None + has_next = queryset_with_cursor.count() > limit + + queryset_subset = list(queryset_with_cursor[:limit]) + + cursor = queryset_subset[-1].id if queryset_subset and has_next else None return { "items": queryset_subset,