#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'm not sure about this.
Slight aside, I'm not sure that ''soft-delete'' isn't an anti-pattern but,
my understanding of this was always that **if** you do implement these
custom managers, you also need to make sure you don't override interfere
with exactly this kind of internal behaviour.
From the docs:
> 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 the first Manager defined in a class
as the “default” Manager, and several parts of Django (including dumpdata)
will use that Manager exclusively for that model. As a result, it’s a good
idea to be careful in your choice of default manager in order to avoid a
situation where overriding get_queryset() results in an inability to
retrieve objects you’d like to work with.
The examples in the docs point to this sort of thing:
{{{
objects = models.Manager() # The default manager.
dahl_objects = DahlBookManager() # The Dahl-specific manager.
}}}
... where we leave the built-in functionality alone and implement our base
filtering (i.e. soft-delete here) in a separate manager.
It seems to me that adding API to ModelAdmin (or needing to override
`get_queryset()` to go via `_base_manager`) to allow correcting for
**not** following the advice here is... well... not the way I'd go, shall
we say.
Not totally against, but that's my thought.
--
Ticket URL: <https://code.djangoproject.com/ticket/29688#comment:2>
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.e077381193bd5aa4e76a9fb07cdd924d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.