For ticket #20625 to allow defining chainable QuerySet on custom model managers. #1284

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

Ticket #20625 - https://code.djangoproject.com/ticket/20625 allows for new functionality as follows:

class OfferManager(models.Manager):
    """ Example of a chainable custom query set """

    ...

    QUERYSET_PUBLIC_KWARGS = {'status__gte': STATUS_ENABLED}
    QUERYSET_ACTIVE_KWARGS = {'status': STATUS_ENABLED}

    ...

    def public(self):
        """ Returns all entries accessible through front end site"""
        return self.all().filter(...)
    public.chainable = True     # instructs to dynamically tranplat this method onto
                                # returned QuerySet as <queryset>.public(...) 
                                # effectively providing chainable custom QuerySets

    def active(self):
        """ Returns offers that are open to negotiation """
        return self.public().filter(**OfferManager.QUERYSET_ACTIVE_KWARGS)
                                    # an example of how to reffer to OfferManager
                                    # constants as 'self' context changes
    active.chainable = True
    ...
Owner

timgraham commented Jul 11, 2013

I think we're going with the approach in #1328

@timgraham timgraham closed this Jul 11, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment