Package: djangorestframework-chain
`django-rest-framework-chain` is an extension to Django REST Framework that allows arbitrary chaining of both relations and lookup filters... image:: https://secure.travis-ci.org/philipn/django-rest-framework-chain.png?branch=master:target: http://travis-ci.org/philipn/django-rest-framework-chainInstallation------------.. code-block:: bash$ pip install djangorestframework-chainRequirements------------* Python 2.6+* Django 1.4.5+Usage-----Chaining filtering through relations~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~To enable chained filtering through relations:.. code-block:: pythonfrom rest_framework import viewsetsimport django_filtersfrom rest_framework_chain import ChainedFilterSet, RelatedFilter# Just a regular FilterSetclass UserFilter(django_filters.FilterSet):username = django_filters.CharFilter(name='username')...class PageFilter(ChainedFilterSet):title = django_filters.CharFilter(name='title')author = RelatedFilter(UserFilter, name='author')# Then just use the PageFilter as you would any other FilterSet:class PageView(viewsets.ModelViewSet):...filter_class = PageFilterthen we can automatically chain our filters through the ``author`` relation, as so::/api/page/?author__username=philipnAllowing any lookup type on a field~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~We can use the ``AllLookupsFilter`` to allow all possible lookup types on a particularfield.  While we could otherwise specify these by hand, e.g.:.. code-block:: pythonclass ProductFilter(django_filters.FilterSet):min_price = django_filters.NumberFilter(name="price", lookup_type='gte')...to allow the ``price__gte`` lookup.  But this gets cumbersome, and we sometimes want toallow any possible lookups on particular fields.  We do this by using ``AllLookupsFilter``:.. code-block:: pythonfrom rest_framework import viewsetsimport django_filtersfrom rest_framework_chain import ChainedFilterSet, AllLookupsFilterclass PageFilter(ChainedFilterSet):title = AllLookupsFilter(name='title')...then we can use any possible lookup on the ``title`` field, e.g.::/api/page/?title__icontains=parkor ::/api/page/?title__startswith=Theand also filter on the default lookup (``exact``), as usual::/api/page/?title=The%20ParkCombining RelatedFilter and AllLookupsFilter~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~We can combine ``RelatedFilter`` and ``AllLookupsFilter``:.. code-block:: pythonfrom rest_framework import viewsetsimport django_filtersfrom rest_framework_chain import ChainedFilterSet, RelatedFilterclass PageFilter(ChainedFilterSet):title = django_filters.CharFilter(name='title')author = RelatedFilter(UserFilter, name='author')# Just a regular FilterSetclass UserFilter(ChainedFilterSet):username = AllLookupsFilter(name='username')...then we can filter like so::/api/page/?author__username__icontains=johnMore information on RelatedFilter~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Recursive relations are supported.  You will need to specify the full modulepath in the ``RelatedFilter`` definition in some cases, e.g.:.. code-block:: pythonclass PersonFilter(ChainedFilterSet):name = AllLookupsFilter(name='name')best_friend = RelatedFilter('people.views.PersonFilter', name='best_friend')class Meta:model = PersonLicense-------Copyright (c) 2013 Philip Neustrom <philipn@gmail.com>Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.