Added an example to the release notes for custom reverse managers.

This commit is contained in:
Loic Bistuer 2014-02-18 23:49:13 +07:00 committed by Tim Graham
parent b4f21d1807
commit 99416c7ad0
2 changed files with 25 additions and 5 deletions

View File

@ -169,7 +169,19 @@ Using a custom manager when traversing reverse relations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It is now possible to :ref:`specify a custom manager It is now possible to :ref:`specify a custom manager
<using-custom-reverse-manager>` when traversing a reverse relationship. <using-custom-reverse-manager>` when traversing a reverse relationship::
class Blog(models.Model):
pass
class Entry(models.Model):
blog = models.ForeignKey(Blog)
objects = models.Manager() # Default Manager
entries = EntryManager() # Custom Manager
b = Blog.objects.get(id=1)
b.entry_set(manager='entries').all()
New system check framework New system check framework
~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -1155,11 +1155,19 @@ query you can use the following syntax::
class Entry(models.Model): class Entry(models.Model):
#... #...
objects = models.Manager() # Default Manager objects = models.Manager() # Default Manager
entries = EntryManager() # Custom Manager entries = EntryManager() # Custom Manager
>>> b = Blog.objects.get(id=1) b = Blog.objects.get(id=1)
>>> b.entry_set(manager='entries').all() b.entry_set(manager='entries').all()
If ``EntryManager`` performed default filtering in its ``get_queryset()``
method, that filtering would apply to the ``all()`` call.
Of course, specifying a custom reverse manager also enables you to call its
custom methods::
b.entry_set(manager='entries').is_published()
Additional methods to handle related objects Additional methods to handle related objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~