#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 Jon Dufresne):
Thanks for the feedback Carlton. On the projects I work on, I've found the
soft delete pattern to be very valuable and successful.
I see the trade off as follows:
Pros
- Never mistakenly display a deleted object (big one)
- Accessing deleted objects is very explicit as a different manager is
used
Cons
- Must override some Django components to use a different manager (e.g.
ModelAdmin.get_queryset())
On the project I work on with sensitive data, the "Never mistakenly
display a deleted object" outweighs the other considerations. So much that
I don't mind overriding the cases that need access to deleted objects.
On a growing team with knowledge gaps made up of diverse skill levels, it
is sometimes hard to always make sure that all code uses the correct
manager. Having the default manager act correct for a large majority of
cases and never mistakenly display deleted data goes a long way to
preventing bugs getting to users. On my project, the introduction of this
pattern sometimes comes immediately after such a bug.
When writing new code it is just too easy and common to reach for
`MyModel.objects...` but one wants `MyModel.active_objects...` or
`MyModel.objects.filter(deleted=False)`. As a result, coding mistakes
happen and bugs get to users.
After reading the quoted text, I think the advice comes down to "be
careful" not "don't do this". I understand the trade offs I'm making.
--
Ticket URL: <https://code.djangoproject.com/ticket/29688#comment:3>
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.0209e51bd02c543fc99ec383b25025eb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.