On Apr 26, 12:33 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote:
> So - here's a slightly modified proposal. Last time this topic came up > on django-dev, Justin Fagnani made an interesting suggestion which I > think will answer your objections, and leaves open some interesting > possibilities for userspace extension. Rather than the > column__aggregate=alias syntax: > > >>> Student.objects.all().annotate( > Avg('height'), tallest=Max('height'), avg_friend_age=Avg('friend__age') > ) > The raw idea - the aggregates themselves are tied up into functions > (Avg, Max, etc) that are constructed as an object. The argument to the > aggregate is the query column, using the standard double-underscore > notation if necessary to cross tables. In QS-RF, this syntax is being > used for cross-table order_by() clauses, so there is an analog there. I like this a lot - makes much more sense to me than the other syntax, and I think I prefer it to my proposed dictionary based syntax as well. > If the aggregate function is provided as an anonymous argument (e.g., > Avg('height')), then the aggregate is asked to provide an appropriate > alias - for example, Avg() might use 'avg__%s' % field_name. If the > aggregate function is provided as a kwarg, the kwarg name is used as > the alias. Is it necessary to provide an anonymous argument syntax at all? Seeing just annotate(Avg('height')) left me confused as to what the alias would be until I read your further explanation. Is there any harm in requiring the user of the API to always explicitly specify their alias using keyword argument syntax? Unless there's a really good reason to provide default aliases I think requiring explicit aliases would be perfectly reasonable ("explicit is better than implicit"). Cheers, Simon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---