Skip to main content

Filter user-data based on multiple criteria.

Project description

https://badge.fury.io/py/django_sieve.png https://travis-ci.org/alixedi/django_sieve.png?branch=master https://pypip.in/d/django_sieve/badge.png

Filter user-data based on multiple criteria.

Installation

We are at the cheeseshop:

pip install django_sieve

Usage

To use django_sieve in a project:

  1. Include it in INSTALLED_APPS in your settings file.

  2. Define a sieve model. A sieve model is the control for defining the filtering criteria for user data. For instance, in our example, we have a bookstore in which a user can subscribe to all the books from a particular author or all the books from a particular publisher. In this case, his book list need to only contain books from the publisher and author that he has chosen. In order to do this, we define a sieve model like so:

    class Sieve(models.Model):
            user = models.ForeignKey('auth.User')
            publisher = models.ForeignKey(Publisher)
            author = models.ForeignKey(Author)
  3. Declare your project-wide sieve model in settings.py. For instance, if the sieve model is called Sieve and resides in the bookstore app:

    SIEVE_MODEL = 'bookstore.Sieve'
  4. Use SieveManager as the ModelManager for all the models in your project that you want to filter based on the criteria defined in the sieve model:

    class Author(models.Model):
            first_name = models.CharField(max_length=30)
            last_name = models.CharField(max_length=40)
            email = models.EmailField()
            objects = SieveManager()
  5. Use the sieve method to define your queryset in your views like so:

    class BookView(ListView):
            queryset = Book.objects.sieve(user=request.user)

That is all. Site-wide filtering of user-data based on pre-defined criteria without having to write queries for all the views. Please be wary of performance issues though - in our experience, django-sieve works for 90% cases especially when you need to bring everything up for a quick demo. However, as your site matures and the number of users increase, you may want to invest in profiling your views and hand-crafting these queries when and where required.

History

0.1.0 (2013)

  • First release on PyPI.

Project details


Download files

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

Source Distribution

django_sieve-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

File details

Details for the file django_sieve-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django_sieve-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9bb74f3ef2d55b79313debb509e440f77f2f5593dc7e04e525eb89fb06c45d6c
MD5 8d03eb9fab8eeec4374efed348a06ef3
BLAKE2b-256 7c38ce85a63f761f425a77cf463601ca80b90747cbcec6f0f1cab8050e03a896

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page