Opened 7 years ago

Closed 6 years ago

Last modified 5 years ago

#13035 closed (fixed)

Wrong documentation for admin and default managers

Reported by: rasca Owned by: Gabriel Hurley
Component: Documentation Version: master
Severity: Keywords: manager objects admin docs
Cc: rasca7@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When creating custom models managers the docs say:

If you use custom Manager objects, take note that the first Manager Django encounters (in the order in which they're defined in the model) has a special status. Django interprets this first Manager defined in a class as the "default" Manager, and several parts of Django (though not the admin application) will use that Manager exclusively for that model. As a result, it's often a good idea to be careful in your choice of default manager, in order to avoid a situation where overriding of get_query_set() results in an inability to retrieve objects you'd like to work with.

So if in a model I have

new = NewManager()
objects = models.Manager()

the admin should work as if there isn't any NewManager but it doesn't

The following works as desired:

objects = models.Manager()
new = NewManager()

Attachments (1)

13035_managers_docs_patch.diff (1.1 KB) - added by Gabriel Hurley 7 years ago.
Fixes some outdated information about default managers and contrib.admin

Download all attachments as: .zip

Change History (9)

comment:1 Changed 7 years ago by Gabriel Hurley

Needs documentation: unset
Needs tests: unset
Owner: changed from nobody to Gabriel Hurley
Patch needs improvement: unset
Status: newassigned
Triage Stage: UnreviewedDesign decision needed

Confirmed that this behavior occurs as reported. I'm not sure which way it's *supposed* to work currently... Whether the code should be brought back in line with the docs or the docs need to be changed to reflect the code!

comment:2 Changed 7 years ago by Gabriel Hurley

Triage Stage: Design decision neededAccepted

Looking at the history of tickets related to admin and _default_manager, it appears this is the intended behavior, and the docs are simply (very) outdated here. I'll add a patch to remove that "though not admin" bit.

Changed 7 years ago by Gabriel Hurley

Fixes some outdated information about default managers and contrib.admin

comment:3 Changed 7 years ago by Gabriel Hurley

Has patch: set

comment:4 Changed 7 years ago by Gabriel Hurley

Summary: Wrong documentaion or bad admin behaviourWrong documentation for admin and default managers

comment:5 Changed 7 years ago by Gabriel Hurley

Component: django.contrib.adminDocumentation

This ended up being a docs bug, so I'm re-categorizing it.

comment:6 Changed 6 years ago by Luke Plant

Resolution: fixed
Status: assignedclosed

(In [12930]) Fixed #13035 - Incorrect documentation regarding admin and default managers

Thanks to rasca for report and gabrielhurley for patch

comment:7 Changed 6 years ago by Luke Plant

(In [12931]) [1.1.X] Fixed #13035 - Incorrect documentation regarding admin and default managers

Thanks to rasca for report and gabrielhurley for patch.

Backport of r12930 from trunk

comment:8 Changed 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top