On Jan 10, 7:10 pm, Carl Meyer <[email protected]> wrote:
> Having access to any manager method from any queryset, regardless of
> which manager that queryset came from, seems to me like a highly
> surprising anti-feature, not a benefit. Can you outline a realistic use
> case for it?

Basically any time when you have multiple managers (due to model
inheritance, for example) and need to mix operations from different
managers. For example you could have an abstract base class
Publishable which defines 'publishable_manager' with one method
"visible(to_user)". Then you might need to mix methods:
News.objects.filter_by_search_params(search_params).visible(request.user)

I do think that having some way to access methods of different
managers is needed. Otherwise if you want to use all the defined
chainable methods in a single queryset, you will need to have them in
single manager. This results in unnecessary manager multi-inheritance.

My next idea is .use_manager(), so that you can change the queryset's
base manager on the fly. This simplifies the implementation, and is
more intuitive to begin with. The above would then be:
News.objects.filter_by_search_params(search_params).use_manager('publishable_manager').visible(request.user)

My API design skills are pretty bad, so other opinions welcome :)

Updated patch at github (https://github.com/akaariai/django/compare/
dynamic_man). It now has use_manager(), and checks methods only from
the manager the QuerySet came from (or from manager set
by .use_manager). It still misses @querymethod. Error messages are
messy, and there are no tests or documentation.

I really have no time to push this forward. I hope the idea is useful.
The patch at github is in good enough state that you can try the API.
Usage is really simple. Clone the branch, and you should be able to
use any manager method which uses self.get_query_set() as its base
query. @querymethod is nothing more than a marker at this point.

 - Anssi

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to