mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Fixed #3871 -- Custom managers when traversing reverse relations.
This commit is contained in:
parent
83554b018e
commit
04a2a6b0f9
6 changed files with 262 additions and 91 deletions
|
@ -92,6 +92,12 @@ The :meth:`QuerySet.as_manager() <django.db.models.query.QuerySet.as_manager>`
|
|||
class method has been added to :ref:`create Manager with QuerySet methods
|
||||
<create-manager-with-queryset-methods>`.
|
||||
|
||||
Using a custom manager when traversing reverse relations
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
It is now possible to :ref:`specify a custom manager
|
||||
<using-custom-reverse-manager>` when traversing a reverse relationship.
|
||||
|
||||
Admin shortcuts support time zones
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -1136,6 +1136,31 @@ above example code would look like this::
|
|||
>>> b.entries.filter(headline__contains='Lennon')
|
||||
>>> b.entries.count()
|
||||
|
||||
.. _using-custom-reverse-manager:
|
||||
|
||||
Using a custom reverse manager
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. versionadded:: 1.7
|
||||
|
||||
By default the :class:`~django.db.models.fields.related.RelatedManager` used
|
||||
for reverse relations is a subclass of the :ref:`default manager <manager-names>`
|
||||
for that model. If you would like to specify a different manager for a given
|
||||
query you can use the following syntax::
|
||||
|
||||
from django.db import models
|
||||
|
||||
class Entry(models.Model):
|
||||
#...
|
||||
objects = models.Manager() # Default Manager
|
||||
entries = EntryManager() # Custom Manager
|
||||
|
||||
>>> b = Blog.objects.get(id=1)
|
||||
>>> b.entry_set(manager='entries').all()
|
||||
|
||||
Additional methods to handle related objects
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
In addition to the :class:`~django.db.models.query.QuerySet` methods defined in
|
||||
"Retrieving objects" above, the :class:`~django.db.models.ForeignKey`
|
||||
:class:`~django.db.models.Manager` has additional methods used to handle the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue