On Fri, Oct 31, 2008 at 4:08 PM, Tonne <[EMAIL PROTECTED]> wrote:
>
> So, what I've done is use Model.objects.values() to limit the returned
> values, which is not ideal as I'm losing the objectness of the
> queryset.
>
> I've worked around the loss Queryset.get_absolute_url by using a less
> than elegant semi-hardcoded url.
>
> So if I'm missing a blindingly obvious way of limiting a query to
> nominated fields so that I can still keep the benefits of a queryset,
> please let me know.

Right at the moment, there is no easy way to retrieve a subset of the
fields on a model _and_ retain the 'modelness' of the data. values()
querysets returns dictionaries, normal querysets return model
instances.

It sounds like ticket #5420 [1] describes the feature you are looking
for; there has been some work on this ticket, but it isn't available
in the trunk yet.

[1] http://code.djangoproject.com/ticket/5420

> Also, is using Model.objects.values() to limit the fields returned
> actually more efficient than Model.objects.all() in terms of database
> hits?

As always, the answer is "it depends", but generally speaking, if you
have a model with a lot of columns (especially a lot of large text
columns), a values() queryset will be more efficient.

The efficiency gains are due to the reduction in the amount of data
that is being retrieved from the database, and the volume of data that
is transmitted. If your database has to do less paging to return
results, and the volume of data that is transmitted is lower, the
results will be retrieved faster. However, if each database record
fits on a single page, or the protocol overhead associated with
returning a row is comparable in size to the row itself, the
efficiency gains will be minimal.

Also, the efficiency gains of using values() will be largely negated
if you end up doing multiple values() calls to retrieve the rest of
the data. If you're going to need all the data anyway, it may be
faster to live with the initial performance hit.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to