Skip to content

Commit

Permalink
docs updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Bishwas-py committed Mar 9, 2024
1 parent f3f2f3d commit c5abbe7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions docs/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ from djapy.pagination import OffsetLimitPagination, paginate

@djapify # required
@paginate(OffsetLimitPagination) # required, OR just @paginate, params: offset=0, limit=10
def todo_list(request) -> List[Todo]:
def todo_list(request, **kwargs) -> List[Todo]:
return Todo.objects.all()
```

Make sure to add `paginate` decorator to your view and pass the pagination class as an argument. `List[Todo]` is the
return type hint of the view, also for Swagger documentation.

> `**kwargs` is required to pass the pagination parameters to the view.
## PageNumberPagination

This is another pagination mechanism in Djapy. It's based on the `page` and `page_size` query parameters. Here's how you
Expand All @@ -33,7 +35,7 @@ from djapy.pagination import PageNumberPagination, paginate

@djapify # required
@paginate(PageNumberPagination) # required, OR just @paginate, params: page_number=1, page_size=10
def todo_list(request) -> List[Todo]:
def todo_list(request, **kwargs) -> List[Todo]:
return Todo.objects.all()
```

Expand All @@ -47,7 +49,7 @@ from djapy.pagination import CursorPagination, paginate

@djapify # required
@paginate(CursorPagination) # required, OR just @paginate, params: cursor=0, limit=10
def todo_list(request) -> List[Todo]:
def todo_list(request, **kwargs) -> List[Todo]:
return Todo.objects.all()
```

Expand All @@ -63,6 +65,7 @@ Here's an example of how you can do that:
from djapy.pagination import BasePagination
from pydantic import model_validator


class CursorPagination(BasePagination): # example
"""Cursor-based pagination."""

Expand All @@ -77,6 +80,7 @@ class CursorPagination(BasePagination): # example
cursor: int | None
limit: int
has_next: bool

# ... your custom fields here

@model_validator(mode="before")
Expand Down

0 comments on commit c5abbe7

Please sign in to comment.