﻿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
9676	Explicit default managers	mrts	Malcolm Tredinnick	"Currently, ""the first manager declared is the default manager"".

However, given the following hierarchy:

{{{
class PublishedObjectManager(models.Manager):
    def get_query_set(self):
        return super(PublishedObjectManager, self).get_query_set()\
                .filter(is_published=True)

class PublicationBase(models.Model):
    ...
    objects = models.Manager()
    published_objects = PublishedObjectManager()

    class Meta:
        abstract = True

class ToplevelPageManager(PublishedObjectManager):
    def get_query_set(self):
        return super(ToplevelPageManager, self).get_query_set()\
                .filter(parent=None)

class PageBase(PublicationBase):
    ...
    toplevel_pages = ToplevelPageManager()

    class Meta:
        abstract = True
}}}

all classes inheriting from `PageBase` get `toplevel_pages` as their
default manager.
To make `objects` default, repetition is necessary:

{{{
class PageBase(PublicationBase):
    ...
    objects = models.Manager()
    toplevel_pages = ToplevelPageManager()

    class Meta:
        abstract = True
}}}

only to specify the default manager. A way to explicitly say
""this is the default manager that should be honoured throughout the
inheritance hierarchy"" would be appropriate. Also, the `_` in front of
`_default_manager` implies that it is an implementation detail, neither is
accessing default managers documented. But all reusable app
writers should really use `model._default_manager` instead of
`model.objects` for any foreign models they must handle.

Generally, there should be an explicit, documented way to set and get
the default manager."		closed	Database layer (models, ORM)	1.0		fixed			Design decision needed	0	1	0	0	0	0
