Skip to content

Commit

Permalink
Add async example in README
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleyoesch committed May 16, 2024
1 parent ad107aa commit d8e1716
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ def posts_api(request, after=None):
'last_cursor': paginator.cursor(page[-1])
}
return data


async def posts_api_async(request, after=None):
qs = Post.objects.all()
page_size = 10
paginator = CursorPaginator(qs, ordering=('-created', '-id'))
page = await paginator.apage(first=page_size, after=after)
data = {
'objects': [serialize_page(p) for p in page],
'has_next_page': page.has_next,
'last_cursor': paginator.cursor(page[-1])
}
return data
```

Reverse pagination can be achieved by using the `last` and `before` arguments
Expand Down

0 comments on commit d8e1716

Please sign in to comment.