Code

Opened 6 years ago

Closed 6 years ago

#6541 closed (fixed)

wrong description of default Manager in documentation

Reported by: Thomas Capricell <django.20.orzelf@…> Owned by: nobody
Component: Documentation Version: master
Severity: Keywords: Manager Model
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 :-)

Attachments (0)

Change History (3)

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

"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.

comment:2 Changed 6 years ago by Thomas Capricell <django.20.orzelf@…>

(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 Changed 6 years ago by ubernostrum

  • Resolution set to fixed
  • Status changed from new to closed

(In [7302]) Fixed #6541: Corrected documentation of how the admin chooses a default manager. Refs #6538.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.