Hi list,
I want to preface this by saying I’m really glad to see the ORM where it is in 1.8, it’s gotten really far and I now think it’s not hopeless to imagine writing complex things in the ORM… So earlier this week I wrote a bit of a rant in the bug tracker about how annotate is confusing (https://code.djangoproject.com/ticket/25834). A short summary is that annotate and values (with a spattering of order_by) are basically what decides grouping, but there’s a lot of trial and error involved in getting the right grouping with a tricky interaction between the two. A behaviour that exemplifies this is that queryset.annotate(foo=thing).annotate(bar=other_thing) is *not* the same as queryset.annotate(foo=thing, bar=other_thing) given certain things. This goes against the intuitive interpretation of the queryset API IMO. I think there should be some update to the API to render grouping more explicit. Absent that, given that the docs are now oriented in a sort of “You shouldn’t need extras anymore” fashion, there really should be a “SQL to ORM” migration guide/cookbook to point out explicitly how to go from SELECT stuff FROM table GROUP BY properties to the right annotate/values. I found what jarshwah pointed out in the ticket was really helpful. Also, some random feature requests: - .values(‘stuff’, my_thing=Coalesce(‘thing’, ‘stuff’)) should work - there should be a provided Year and Month functions to extract years/months from date fields Anyways I wanted to share this experience so that anyone who has the courage to right new docs/continue evolving things can know of at least one team’s difficulties. Raphael -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/8d175352-d15e-4dc2-a471-014d6b0bc3e2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
