Re: Filter aggregation results

2009-07-20 Thread Russell Keith-Magee

On Tue, Jul 21, 2009 at 3:11 AM, Michel Thadeu
Sabchuk wrote:
>
> Hi guys,
>
> Is there a way to filter an aggregation? Suppose the following code:
>
> Book.objects.annotate(num_authors=Count('authors')).order_by
> ('num_authors')
>
> How can I count only masculine authors or authors by age? I think a
> cool way could be:
>
> Book.objects.annotate(
>   num_authors=Count('authors').filter(is_masculine=True
> ).order_by('num_authors')
>
> This should be evaluated to a subselect. Anyway, this doesn't work. I
> think the only way is to use an extra clause on the select, am I
> right?

A subselect isn't the only way, but it would certainly be one way.
Your syntax proposal is also interesting - but more interesting would
be a working implementation. It's easy to make syntax proposals, but a
lot harder to turn those proposals into code. :-)

There are a few bugs lingering in the aggregation code, and almost all
of them relate to the interaction of filters and joins. Finding the
right way to express these edge cases in SQL - and then, how to
differentiate between these cases in Django's ORM - will be an ongoing
project into v1.2 and beyond. Any assistance on this front is most
welcome.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Filter aggregation results

2009-07-20 Thread Michel Thadeu Sabchuk

Hi guys,

Is there a way to filter an aggregation? Suppose the following code:

Book.objects.annotate(num_authors=Count('authors')).order_by
('num_authors')

How can I count only masculine authors or authors by age? I think a
cool way could be:

Book.objects.annotate(
   num_authors=Count('authors').filter(is_masculine=True
).order_by('num_authors')

This should be evaluated to a subselect. Anyway, this doesn't work. I
think the only way is to use an extra clause on the select, am I
right?

Thanks in advance,

--
Michel Sabchuk
http://turbosys.com.br/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---