﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20625	Custom Chainable QuerySets	Daniel Sokolowski	loic84	"Provide a mechanism for defining chainable custom QuerySet directly through a subclassed `models.Manager` definition instead of the current approach that requires a custom `models.Manager` + `QuerySet` pair. This ticket potentially replaces/complements https://code.djangoproject.com/ticket/16748. 

I suggest that we allow defining chainable querysets by allowing the django programmer to add a `chainable == True` attribute to the custom queryset method. The proposed syntax would look as shown below and a working github pull request will be submitted shortly; thoughts and feedback welcomed.

{{{
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
    ...
}}}"	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed	QuerySet, models.Manager, chainable	loic@… mike@…	Accepted	1	0	0	0	0	0
