tomchristie/django-rest-framework — pull request #1167 by copitux (2013-10-10 12:37:00+00:00)
Title: Pagination offset and link

## Add support to two additional pagination behaviours

They have been developed as a mixins, but we'd refactor it to a pagination layer decoupled from views (and we can use ``DEFAULT_PAGINATION_BEHAVIOUR = 'pages' or 'offset' or 'link'`` in settings)

If you like it, we'd continue develop tests

### Link

Use [Link header](http://tools.ietf.org/html/rfc5988) to include the pagination info (like [github api does](http://developer.github.com/v3/#pagination))

```python
# [test_app.views.py]
from rest_framework import mixins, generics
class List(mixins.LinkPaginationMixin, generics.ListAPIView):
model = test_app.Model
```

```
GET api/collection/?page=2

HTTP 200 OK
...
Link: ; rel="next", ; rel="last", ; rel="first", ; rel="prev"

[
# resources
]
```

### Offset & Limit

Paginate by ``offset`` and ``limit`` like SQL does, instead of ``page`` and ``per_page`` (delegate the calc to the end user)

```python
# [test_app.views.py]
from rest_framework import mixins, generics
class List(mixins.OffsetLimitPaginationMixin, generics.ListAPIView):
model = test_app.Model
```

```
GET api/collection/?offset=2&limit=4

HTTP 200 OK
...
{
'count': 20
'results': [
{resource_2},
{resource_3}
]
}
```