Second try. I promise there won't be a third.

Is there a rationale for multiple managers per model? Or is it a  
that's-how-it's-always-been thing?
If I missed something obvious, I would have received a "wrong list or  
rtfm" reply by now, supposedly.

{{{
class AManager(Manager):
     pass

class BManager(Manager):
     pass

class A(Model):
     a_objects = AManager()
     class Meta:
         abstract = True

class B(Model):
     b_objects = BManager()
     class Meta:
         abstract = True

class C(A,B):
     objects = Manager()

class D(B,A):
     objects = Manager()
}}}

Now C._default_manager == C.a_objects and D._default_manager ==  
D.a_objects.
If A and B come from different modules _default_manager will be  
picked depending on import order.

If this is by design, I'd be happy with a "wontfix" reply. I'm not  
using multiple managers anyway.

[1] http://code.djangoproject.com/ticket/7154



Am 31.05.2008 um 19:16 schrieb Johannes Dollinger:

>
> I'd like to propose a change of the Model.defaul_manager concept. My
> first concern was the inability to control the default_manager when
> subclassing a Model that already provides a default_manager (the base
> class' manager will be added before the subclass' manager).
>
> This could be solved by either an explicit default_manager
> declaration in Meta,
>
> my_manager = MyManager()
> class Meta:           
>       default_manager = 'my_manager'
>       
> or the convention that default_managers are called `objects` (then
> you wouldn't even need the default_manager concept).
> I strongly favour the latter, because it's dry and simple. Yet it's a
> backwards incompatible change ..
>                       
> My attempts to come up with a good example to illustrate my proposal
> were in vain - and I begin to think, that it's always cleaner to keep
> a single Manager (and subclass as necessary) and never ever alter
> Manager.get_query_set() behaviour (or all() for that matter). Does
> anybody have a good use-case that depends on multiple managers?
>
> Here is how I would write the custom manager doc example (from [1]):
> http://dpaste.com/53948/ (Those proxy methods could use a little meta-
> programming.).
>
> Has this approach any flaws? If not, shouldn't the docs advertise
> this more flexible approach instead of multiple Managers?
>
> ___
> Johannes
>       
> [1] http://www.djangoproject.com/documentation/model-api/#custom-
> managers
>
>
> >



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
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