Opened 17 years ago
Closed 17 years ago
#6541 closed (fixed)
wrong description of default Manager in documentation
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Keywords: | Manager Model | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
On http://www.djangoproject.com/documentation/model-api/#modifying-initial-manager-querysets it is written
"If you use custom Manager objects, take note that the first Manager Django encounters (in order by which they’re defined in the model) has a special status. Django interprets the first Manager defined in a class as the “default” Manager. Certain operations — such as Django’s admin site — use the default Manager to obtain lists of objects, so it’s generally a good idea for the first Manager to be relatively unfiltered."
It doesn't work here, and it seems the code has changed in trunk with respect to this.
On irc i've been told to do "manager =" in class Admin, and indeed it works. They also asked me to report it here :-)
Change History (3)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
(Sorry, i was in a hurry)
With the following code, the admin interface will not use MoniteurManager, but the usual, unfiltered, default one.
class MoniteurManager(models.Manager):
def get_query_set(self):
raise ValueError
return super(MoniteurManager,self).get_query_set().filter(anneein=[1,2,3])
class Moniteur(models.Model):
objects_current = MoniteurManager()
annee = models.IntegerField("Année", choices=ANNEE_CHOICES, default='1', core=True)
class Admin:
etc....
It works if i do :
class Moniteur(models.Model):
class Admin:
manager = MoniteurManager()
comment:3 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
"it doesn't work" is not really specific enough to work on this problem. What exactly are you doing and what doesn't work? That is, please give us some steps to duplicate the problem. A small example (a model with one field, say), would be ideal.