You're right about that. You can aggregate over custom expressions. For
aggregating over enums you should be able to use case expressions

On Wed, 5 Aug 2015 at 05:05 Anssi Kääriäinen <akaar...@gmail.com> wrote:

> On Tuesday, August 4, 2015, Shai Berger <s...@platonix.com> wrote:
>>
>> The classic database aggregation examples involve aggregation over time:
>> Sum
>> of sales per quarter (which is, itself, a function over date); average
>> temparature per month; etc. All these require group-by clauses which name
>> (expressions over) columns which are not FKs.
>>
>>
> The following should work:
>
>
>  
> qs.annotate(quarter=Quarter('sold_date')).values('quarter').annotate(sum=Sum('amount'))
>
> I recall some changes to how the group by expression is generated for
> expressions. If I recall correctly the group by should have the expression
> itself now, not the base columns of the expression.
>
> There are many similar examples involving "enum columns" -- columns with a
>> limited set of choices, where the choices are not instances of another
>> model.
>
>
> I'm not sure of this one.
>
>  - Anssi
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-developers/FojuU0syO8Y/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> 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/CALMtK1FqTkdmnXNYvjZ8U_QF9%2BWzrMCb1DDFQU5WB4SiKPX06g%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-developers/CALMtK1FqTkdmnXNYvjZ8U_QF9%2BWzrMCb1DDFQU5WB4SiKPX06g%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/CAPbDM0dLTZTBzZUcPPTY_4S9BympXtkm%3D%3DsNr1pZNYDxeauzMQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to