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

Chainable methods on Model managers

Project Description

Allows chaining of custom model Manager methods, without jumping through QuerySet hoops.

Installing

Simply install the package using pip:

pip install django-chainable-manager

Using

Create a Manager that extends chainablemanager.ChainableManager:

from django.db import models
from chainablemanager.manager import ChainableManager

class PostManager(ChainableManager):
    class QuerySetMixin(object):
        def published(self):
            return self.filter(publish_date__gte=datetime.date.today())

        def written_by(self, user):
            return self.filter(author=user)

class Post(models.Model):
    title = models.CharField(max_length=255)
    content = models.TextField()
    publish_date = models.DateField()
    author = models.ForeignKey('auth.User')

    objects = PostManager()

Now use it where ever you need it:

from .models import Post

my_published_posts = Post.objects.written_by(request.user).published()
Release History

Release History

This version
History Node

0.5.0

History Node

0.4.0

History Node

0.3.1

History Node

0.3.0

History Node

0.2.0

History Node

0.1.1

History Node

0.1.0

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
django-chainable-manager-0.5.0.tar.gz (3.7 kB) Copy SHA256 Checksum SHA256 Source Jan 20, 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