#29688: ModelAdmin: Add attribute to override manager used by
ModelAdmin.get_queryset()
-------------------------------+--------------------------------------
     Reporter:  Jon Dufresne   |                    Owner:  nobody
         Type:  New feature    |                   Status:  new
    Component:  contrib.admin  |                  Version:  master
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  1              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------

Comment (by Carlton Gibson):

 I think in this case overriding `get_queryset()` leads to simpler, more
 straightforward code, that more clearly expresses your intent, and is
 ultimately more maintainable.
 Even if you have to write a few more lines. Basically I think we're beyond
 the sweet spot of these kind of declarative options here. (But this isn't
 something we need to agree on now.)

 My preferred option here is very much to not add extra API. (But mine is
 just one opinion.)

 > What if it remained an undocumented API?

 Well that's one idea. :-)

 If we add it, there's no problem with it being documented but I think it
 should just say something along the lines of...


 {{{
 .. attribute:: ModelAdmin.manager_name

      Default, ``'_default_manager'``. Set this to the name of the model's
 manager to be used
      by :meth:`.ModelAdmin.get_queryset()` if the default manager is not
 appropriate for your needs.
 }}}

 i.e. nice and vague, but there if you already know what all the terms
 mean.

 **If** we have an example then I think that should be of the `DahlManager`
 type, i.e. creating an Admin restricted to a filtered queryset, not one
 showing the very pattern we warn against, where you filter the default
 queryset in the default manager.

 (Why not that? Because people will be doing
 [https://docs.djangoproject.com/en/2.1/intro/tutorial02/ Tutorial 2], see
 this pattern in the Admin docs, put it in their code, and give themselves
 all sorts of trouble.)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29688#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.4af9da8475327bec4aaacecdea816377%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to