#9676: Explicit default managers
------------------------------------------+---------------------------------
Reporter: mrts | Owner: nobody
Status: new | Milestone:
Component: Database layer (models, ORM) | Version: 1.0
Keywords: | Stage: Unreviewed
Has_patch: 0 |
------------------------------------------+---------------------------------
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.
--
Ticket URL: <http://code.djangoproject.com/ticket/9676>
Django <http://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 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---