Opened 9 years ago
Last modified 9 years ago
#23533 new New feature
Hook for default QuerySet filtering defined on the QuerySet itself.
Reported by: | Loic Bistuer | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Django 1.7 brought managers automatically created from QuerySet
which replaces defining a custom manager for the purpose of defining reusable methods. Refs #20625.
One use-case remains inelegant: using a custom QuerySet
with default QuerySet
customization/filtering:
BaseCustomManager = Manager.from_queryset(CustomQueryset) class CustomManager (BaseCustomManager ): def get_queryset(self): queryset = super(Manager, self).get_queryset() return queryset.filter(...)
This ticket proposes adding a hook on QuerySet
to enable this without requiring a custom Manager
.
Change History (2)
comment:1 Changed 9 years ago by
comment:2 Changed 9 years ago by
Triage Stage: | Unreviewed → Accepted |
---|
Note: See
TracTickets for help on using
tickets.
It's worth noting that
QuerySet.__init__()
can't be used for providing such initialization/customization:__init__
can't return a different instance.So far the best option I can think of is a hook called externally by the manager.
POC with a
QuerySet.get_initial_queryset()
method https://github.com/loic/django/compare/ticket23533