Jacob argued on #django-dev that you can already achieve the only()
behaviour by overriding ModelAdmin.queryset().
So I experimented with that. "The results were disappointing," as prof.
Denzil Dexter from The Fast Show used to say :) .
Adding the following to CAdmin
def queryset(self, request):
qs = super(CAdmin, self).queryset(request)
return qs.only('name', 'is_published',
'a', 'b').select_related()
results in correct SQL, but due to bug #10710 [1] fields are shuffled
and the resulting view is the worst possible: contents of *the large
text field* are displayed in the changelist instead of __unicode__ --
which strikes me as a cruel April fools trick, except today is April 3:
http://img3.imageshack.us/img3/4295/afterlimitqueryset.png
Ideally,
def queryset(self, request):
qs = super(CAdmin, self).queryset(request)
return qs.only('name', 'is_published',
'a', 'b').select_related('a__name', 'b__name')
should work, but due to the same bug [1] that throws
FieldDoesNotExist: A has no field named 'b'.
I expect that [1] is more or less easy to fix and overriding queryset()
in that manner will be eventually possible.
However, the conceptual question of whether we should do that by default
remains open. That is, should we really SELECT(*) if we know in advance
that only the fields in list_display will be displayed? Jacob argues
that current behaviour is OK, admin is "fast enough" and queryset() can
be used for advanced things -- which is a valid position, so I won't
campaign further for the "optimal by default" cause. But the "10 users
opening a default admin changelist page of 100 entries for objects that
contain 100 KB of data (100 MB of memory use), only to display e.g. the
couple of bytes in object title" case makes me still uncomfortable.
As an aside, note that queryset() is undocumented [2].
[1] http://code.djangoproject.com/ticket/10710
[2] http://code.djangoproject.com/ticket/10712
Can you please stop? We all get that you think these tickets are
important. They're on the milestone for 1.1, so they'll be fixed.
Nagging us here doesn't help get your tickets pushed to the front of
the queue.
Jacob
The reason Jacob asked you to stop is that posts of this nature do
nothing to assist in the process of closing tickets.
The Contribution FAQ [1] specifically covers this issue. From the last
point of [1]:
"Don’t post to django-developers just to announce that you have filed
a bug report. All the tickets are mailed to another list
(django-updates), which is tracked by developers and triagers, so we
see them as they are filed."
If you can demonstrate that a changeset hasn't closed a bug, and a
problem still exists, you should either reopen the relevant ticket in
Trac or open a new issue that describes the missing edge case. If you
find a completely new problem, it should be logged in Trac.
If you have a patch that you think will resolve a problem, attach it
to the ticket, and mark the ticket has having a patch. Ideally, this
should be a patch _with_ tests. A patch without tests is essentially
useless from a review perspective. Again, this is also covered in the
FAQ [2].
Posting to django-developers won't cause us to look at your tickets
any faster. We already have a list of things that we need to look at -
it's called the v1.1 todo list [3], and your tickets are already on
that list.
[1] http://docs.djangoproject.com/en/dev/internals/contributing/#id1
[2] http://docs.djangoproject.com/en/dev/internals/contributing/#patch-style
[3] http://code.djangoproject.com/query?status=new&status=assigned&status=reopened&group=component&milestone=1.1&order=priority
Yours,
Russ Magee %-)