Opened 18 years ago
Closed 18 years ago
#2609 closed defect (fixed)
CurrentSiteManager needs models.Manager() for admin to function.
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | normal | Keywords: | CurrentSiteManager |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When using the CurrentSiteManager in your objects you must include the models.Manager() for the admin interface to work. In the docs on the "sites" framework under The CurrentSiteManager the Photo object example is given. In this example the CurrentSiteManager and the models.Manager() are both explicitly defined so this works. If you do not define the models.Manager() when you use the CurrentSiteManager the admin interface will fail with a ChangeManipulator error (contrib/admin/views/main.py line 317). Nowhere in the docs does it state that you must define both. I think that this is an error since the models.Manager() should still be automatically created even if you use a CurrentSiteManager. A workaround is to define both as shown in the example.
Change History (5)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
This isn't an error, but the docs could do a better job of pointing at the documentation for custom managers, which does explain that the first manager defined for a model will be the default one, and that defining one or more custom managers will cause the "automatic" objects
manager not to be created for you, so that you'll have to create it manually if you want to keep it.
comment:3 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 by , 18 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Actually, the documentation is somewhat wrong ...
The administration doesn't use the appropriate object all of the time ... check out line 216 of db/models/options.py
self.manager = manager or Manager()
This manager gets used in a number of places, more importantly it gets used by the ChangeList class for the admin interface, so the change list shows instances of the model for all sites, regardless of whether your CurrentSiteManager is first or not ...
I hope you don't mind that I'm re-opening the ticket. At the very least, the documentation should be updated.
comment:5 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Not only do you need to define the models.Manager but you must use the same order as in the example or even that won't work.
For example, this works:
This doesn't: