# Pagination

Paginate large datasets - automatically for QuerySet properties, or manually
with Django's Paginator.

## Basic usage

```interlace-demo
PaginationDemo
```

## Automatic QuerySet pagination

A property holding a QuerySet is paginated automatically. Drive it with
`<name>_page` and `<name>_per_page` properties
(default 15 per page) - the template just iterates the property and receives the
current page.

```python
from django.db.models import QuerySet

class PostList(Component):
    posts: QuerySet = None
    posts_page: int = 1
    posts_per_page: int = 10

    def mount(self):
        self.posts = Post.objects.order_by('-created_at')

    def next_page(self):
        self.posts_page += 1
```

## Load more

Append the next page instead of replacing - accumulate into a list and track
whether more remain.

```python
from django.core.paginator import Paginator

class Feed(Component):
    posts: list = []
    page: int = 1
    has_more: bool = True

    def mount(self):
        self.load()

    def load(self):
        page_obj = Paginator(Post.objects.all(), 20).get_page(self.page)
        self.posts.extend(list(page_obj))
        self.has_more = page_obj.has_next()

    def load_more(self):
        self.page += 1
        self.load()
```
