#20625: Custom Chainable QuerySets -------------------------------------+------------------------------------- Reporter: danols | Owner: danols Type: New feature | Status: assigned Component: Database layer | Version: master (models, ORM) | Resolution: Severity: Normal | Triage Stage: Keywords: QuerySet, | Unreviewed models.Manager, chainable | Needs documentation: 0 Has patch: 1 | Patch needs improvement: 0 Needs tests: 0 | UI/UX: 0 Easy pickings: 0 | -------------------------------------+------------------------------------- Changes (by danols):
* has_patch: 0 => 1 Comment: Properly formatted usage code example: {{{ 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 ... }}} -- Ticket URL: <https://code.djangoproject.com/ticket/20625#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.a0e9edc24a9e22cca1b8ba91c880508f%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.