#20625: Custom Chainable QuerySets
-------------------------------------+-------------------------------------
     Reporter:  danols               |                    Owner:  loic84
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:  QuerySet,            |      Needs documentation:  1
  models.Manager, chainable          |  Patch needs improvement:  1
    Has patch:  1                    |                    UI/UX:  0
  Needs tests:  1                    |
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by loic84):

 @akaariai: I'm glad you presented this idea; I find `as_manager()` very
 elegant as it removes all the boilerplate from `Manager` while remaining
 backward compatible, it's probably more efficient as well.

 Its semantic is already used throughout Django (`View.as_view()`,
 `Form.as_p()`, etc.) so people should feel right at home.

 Regarding the copy logic, I see you've used the "opt in" strategy from my
 initial patch, as per @danols' suggestion I like better the "opt out with
 smart defaults" one.

 I had a stab at it:
 https://github.com/loic/django/compare/loic:ticket20625_copy

 {{{
 class MyQuerySet(models.QuerySet):
     # Private methods are ignored by default.
     def _foo(self):
         return ...

     # Public methods are copied by default.
     def foo(self):
         return ...

     # Opt in.
     def _bar(self):
         return ...
     _bar.manager = True

     # Opt out.
     def bar(self):
         return ...
     bar.manager = False

 class MyModel(Model):
     objects = MyQuerySet.as_manager()
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20625#comment:21>
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.4f7b6fe5138acd69c6a5e2dd3517d8e8%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to