#10712 closed (fixed)
ModelAdmin.queryset() is undocumented.
Reported by: | mrts | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.0 |
Severity: | Keywords: | efficient-admin | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
However, it is extremely useful and advocated by e.g. James in http://www.b-list.org/weblog/2008/dec/24/admin/ .
Attachments (1)
Change History (12)
comment:1 by , 16 years ago
milestone: | → 1.1 |
---|---|
Needs documentation: | set |
comment:2 by , 16 years ago
Ideally, the following use cases would be documented:
- show only objects owned by the logged-in user (by James):
def queryset(self, request): if request.user.is_superuser: return Entry.objects.all() return Entry.objects.filter(author=request.user)
- defer large fields that would otherwise slow down the changelist view and cause it to consume memory (#10710 needs to be fixed for this to work):
def queryset(self, request): qs = super(...).queryset(request) return qs.only('list_display_field_1', 'list_display_field_2').select_related().only('related__field_used_in_string_representation')
comment:3 by , 16 years ago
Keywords: | efficient-admin added |
---|
The second use-case should wait for #10742 and #10733.
The proper incantation should actually be in the lines of the following:
class C(Base): name = models.CharField(max_length=10) is_published = models.BooleanField() a = models.ForeignKey(A, blank=True, null=True) b = models.ForeignKey(B) class CAdmin(admin.ModelAdmin): list_display = ('name', 'a', 'b', 'is_published') list_select_related = None def queryset(self, request): qs = super(CAdmin, self).queryset(request) return qs.only('name', 'is_published', 'a__name', 'b__name').select_related('a', 'b')
comment:4 by , 16 years ago
milestone: | 1.1 |
---|
comment:5 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:7 by , 15 years ago
Has patch: | set |
---|
comment:8 by , 15 years ago
milestone: | → 1.2 |
---|---|
Needs documentation: | unset |
Triage Stage: | Accepted → Ready for checkin |
would be nice to get this in 1.2 if possible, the second use case above should probably be broken off to a separate ticket
comment:9 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:10 by , 15 years ago
Note:
See TracTickets
for help on using tickets.
Tentatively pushing to 1.1, feel free to push to 1.2.