Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A better way than DRF proposed for do some basic filters

Project Description


A better way than DRF proposed for do some basic filters


  • Python (2.7,3.2,3.3,3.4, 3.5 -with Django 1.8-)
  • Django (1.7, 1.8)
  • Django REST Framework (3.0, 3.1, 3.2)


Install using pip

$ pip install drf-lafv


Imagine that you have the following

from django.db import models

class Author(models.Model):
    name = models.CharField(max_length=250)
    nickname = models.CharField(max_length=100)

class Book(models.Model):
    title = models.CharField(max_length=200)
    description = models.TextField()
    publication_date = models.DateField()
    isbn = models.CharField(max_length=17)
    author = models.ForeignKey(Author)

And you want to filter your list of books by author’s nickname, isbn and create a custom filter which will allow to get you books that were published less than 30 days ago. Well, DRF per se, ask you to install django-filter and write a bunch of stuff that maybe hard. With lafv you can accomplish this doing this:

from lafv.views import ListAPIFilteredView
from serializers import BookSerializer

class BookView(ListAPIFilteredView):
    queryset = Book.objects.all()
    serializer_class = BookSerializer
    filter_fields = ('author__nickname', 'isbn')
    custom_filters = ('new', )

    def filter_new(self, queryset):
        get books that publication date is no longer than 1 month
        last_month = - timedelta(days=30)
        queryset = queryset.filter(publication_date__gte=last_month)
        return queryset

And that’s it!, please check the examples on the test app


Install testing requirements.

$ pip install -r requirements.txt

Run with runtests.

$ ./

You can also use the excellent tox testing tool to run the tests against all supported versions of Python and Django. Install tox globally, and then simply run:

$ tox


To build the documentation, you’ll need to install mkdocs.

$ pip install mkdocs

To preview the documentation:

$ mkdocs serve
Running at:

To build the documentation:

$ mkdocs build
Release History

Release History

This version
History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
drf_lafv-0.0.2-py2.py3-none-any.whl (3.0 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Oct 15, 2015
drf-lafv-0.0.2.tar.gz (3.9 kB) Copy SHA256 Checksum SHA256 Source Oct 15, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting