On Fri, 15 Feb 2008 01:54:24 -0800 (PST)
Dima Dogadaylo <[EMAIL PROTECTED]> wrote:
> > Of course, this decreases database load, but IMHO it is better to
> > use QuerySet.values if you want select just certain values from a
> > model.
> 
> Often I need methods defined in models and isn't available at
> dictionaries.
> For example get_avatar_url().

These methods might change and don't will work anymore, if the now
required fields are not selected by QuerySet.fields. So you have to
look for all occurrences in your code and change the parameter list of
QuerySet.fields, after figuring out which fields are required. This is
why I think it would be more straight forward to write your functions
independent from the model and pass the required values (as retrieved
by QuerySet.values) as separate arguments if you are going to avoid
selecting more data than required.

But on the other hand it is ugly to extract logic which relates to a
model from the model. But an ORM always has performance drawbacks in
favor of strict design. So I would rathe omit this performance feature
in favor of strict desgings, since incomplete models as created by
QuerySet.fields might introduce as many problems as the performance
increase.

> I used standard Django lookup syntax, but because in trunk Djnago
> don't support selecting of related fields, I thought it's better to
> respect DRY principe and write:
> entries = Entry.objects.values('headline', user__address=('country',
> 'city', 'zip'))
> 
> than
> entries = Entry.objects.values('headline', 'user__address__country',
> 'user__address__city', 'user__address__zip').
> 
> Also please note, currently lookups with 2 underscores are used only
> in **kwargs, because it don't have many sense as quoted string (even
> current QuerySet.order_by() uses '.' instead of '__' as separator). So
> from design and usability point of view my form of selecting related
> fields is better, I think.

Ok, I agree. I would like to getting this feature merged in trunk, too.

Regards
Sebastian Noack

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to