Opened 16 years ago
Last modified 16 months ago
#10761 assigned New feature
ModelAdmin.queryset() is missing a mechanism for specifying different querysets for changelist and change object views
Reported by: | mrts | Owned by: | Tom Carrick |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | efficient-admin |
Cc: | marcoberi@…, andy@…, Jeongsoo, Park | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Pull Requests: | How to create a pull request | ||
Description ¶
ModelAdmin.queryset()
is used both in the changelist and change object views.
Suppose some fields are deferred in the returned queryset to speed up changelist rendering. As a result, the object change view has to perform additional queries for all the deferred fields to pull them in.
The proposed solution is to add another parameter to queryset()
that specifies whether a changelist or change object queryset should be returned as follows:
def queryset(self, request, for_change_object_view=False):
According to the ticket's flags, the next step(s) to move this issue forward are:
- To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is:
[https://github.com/django/django/pull/#### PR]
.
Change History (13)
comment:1 by , 16 years ago
Keywords: | efficient-admin added |
---|
comment:2 by , 16 years ago
comment:3 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 16 years ago
#11019 is in essence a duplicate, i.e. it calls for a broader .queryset()
refactor.
comment:6 by , 15 years ago
Cc: | added |
---|
Besides queryset, I would also like to have an hook to customize, for example, list_display and list_filter in a cleaner way than this (mine ugly code follows):
def category_changelist_view(self, request, extra_context=None, category=None): backup_list_filter = self.list_filter[:] backup_list_display = self.list_display[:] backup_queryset = self.queryset self.list_filter = None self.list_display.remove('category') self.queryset = curry(self.category_queryset, category=category) ret = super(PVCataAdmin, self).changelist_view(request, extra_context) self.list_filter = backup_list_filter self.list_display = backup_list_display self.queryset = backup_queryset return ret def get_urls(self): urls = super(CategoryAdmin, self).get_urls() urls_categories = patterns('', *tuple( ((r'%s/$' % categories), self.admin_site.admin_view( curry(self.categories_changelist_view, category=category.pk))) for category in Category.objects.all()) ) return urls_categories + urls
comment:7 by , 15 years ago
Cc: | added |
---|
comment:8 by , 15 years ago
milestone: | 1.2 |
---|
1.2 is feature-frozen, moving this feature request off the milestone.
comment:9 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:12 by , 4 years ago
Cc: | added |
---|
comment:13 by , 16 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Looking around a bit more, the same queryset is also used in several other places (e.g. for actions and delete view), so the parameter is suboptimal. A holistic design is needed.
One option would be to amend
ModelAdmin
as follows:The
queryset_for_...
would be used in appropriate places. This is also backwards-compatible.