On 14 Feb, 17:26, Sebastian Noack <[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(). > That QuerySet.values can not select values from related fields, annoys > myself, too. But your implementation is a bit restricted. Here > the example from your blog: > > entries = Entry.objects.values('headline', user=('username',))[:10] > > A syntax as following would be more straight forward: > > entries = Entry.objects.values('headline', 'user__username')[:10] 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. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---