Mimicking the Django ORM queryset over rest framework api
Project description
[![Build Status](https://travis-ci.org/variable/django-rest-framework-queryset.svg?branch=master)](https://travis-ci.org/variable/django-rest-framework-queryset)
# Django Rest Framework QuerySet
Mimicking the Django ORM queryset over rest framework api
## Usage:
### normal operation
```python
from rest_framework_queryset import RestFrameworkQuerySet
from django.core.paginator import Paginator
qs = RestFrameworkQuerySet('http://localhost:8082/api/')
qs.all()
# filter
boys = qs.filter(gender='boy')
girls = qs.filter(gender='girls')
# slicing
first_100_boys = boys[:100]
# pagination
p = Paginator(qs, 10)
print p.count
print p.num_pages
page1 = p.page(1)
```
### class based view
```python
from django.views.generic import ListView
from rest_framework_queryset import RestFrameworkQuerySet
class ListDataView(ListView):
paginate_by = 10
template_name = 'list.html'
def get_queryset(self, *args, **kwargs):
return RestFrameworkQuerySet('http://localhost:8082/api/').filter(**self.request.GET.dict())
```
## Dependencies
The queryset is dependent on the API that uses [LimiteOffsetPagination](http://www.django-rest-framework.org/api-guide/pagination/#limitoffsetpagination)
If you are using [PageNumberPagination](http://www.django-rest-framework.org/api-guide/pagination/#pagenumberpagination) then you can use the included `rest_framework_queryset.pagination.HybridPagination` which will switch pagination class depends on the query param is passed.
# Django Rest Framework QuerySet
Mimicking the Django ORM queryset over rest framework api
## Usage:
### normal operation
```python
from rest_framework_queryset import RestFrameworkQuerySet
from django.core.paginator import Paginator
qs = RestFrameworkQuerySet('http://localhost:8082/api/')
qs.all()
# filter
boys = qs.filter(gender='boy')
girls = qs.filter(gender='girls')
# slicing
first_100_boys = boys[:100]
# pagination
p = Paginator(qs, 10)
print p.count
print p.num_pages
page1 = p.page(1)
```
### class based view
```python
from django.views.generic import ListView
from rest_framework_queryset import RestFrameworkQuerySet
class ListDataView(ListView):
paginate_by = 10
template_name = 'list.html'
def get_queryset(self, *args, **kwargs):
return RestFrameworkQuerySet('http://localhost:8082/api/').filter(**self.request.GET.dict())
```
## Dependencies
The queryset is dependent on the API that uses [LimiteOffsetPagination](http://www.django-rest-framework.org/api-guide/pagination/#limitoffsetpagination)
If you are using [PageNumberPagination](http://www.django-rest-framework.org/api-guide/pagination/#pagenumberpagination) then you can use the included `rest_framework_queryset.pagination.HybridPagination` which will switch pagination class depends on the query param is passed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-rest-framework-queryset-0.0.15.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a43356a4016d85b97a015a42aaccd72893153386dfb175cbb540134a4db42aab |
|
MD5 | 85bd6c581c87b6409bb4dd61f5966ecf |
|
BLAKE2b-256 | 3f32fdc735f68f5bbc39e04811397945968ceafc990602e32e9a3518d1e48ba7 |
Close
Hashes for django_rest_framework_queryset-0.0.15-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adcd98f00e197f408180a8c7db9bef9c85dce688ffca97cbf92078fe5f06a9ec |
|
MD5 | 42fac376b8fadaf420d3da9bcbf2a31e |
|
BLAKE2b-256 | 6d6ab9e70f65122bfdfb6a4905e787423df8bf3b166b8f5805a5084177c765a3 |