Skip to content
This repository has been archived by the owner on Jul 29, 2018. It is now read-only.

Mimicking the Django ORM queryset so that can be used ListViews for pagination

License

Notifications You must be signed in to change notification settings

NHLibertyAlliance/django-rest-framework-queryset

 
 

Repository files navigation

Build Status

Django Rest Framework QuerySet

Mimicking the Django ORM queryset over rest framework api

Usage:

normal operation

    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

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 If you are using PageNumberPagination then you can use the included rest_framework_queryset.pagination.HybridPagination which will switch pagination class depends on the query param is passed.

About

Mimicking the Django ORM queryset so that can be used ListViews for pagination

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%