Skip to main content

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()

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-chainable-manager-0.5.0.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file django-chainable-manager-0.5.0.tar.gz.

File metadata

File hashes

Hashes for django-chainable-manager-0.5.0.tar.gz
Algorithm Hash digest
SHA256 14ee56784f3985566e0be48cba1fbc985e392b1ee339787c23f9041ccc150230
MD5 b8e86fe00a1b3958bb07db856ae01ab8
BLAKE2b-256 a2040fc558e70f5b8a0287f5162faf67e9ee48898cb96c7a88a14ddf75cfc6e8

See more details on using hashes here.

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