On Fri, May 15, 2009 at 9:24 PM, Andy Mikhailenko <neith...@gmail.com>wrote:

>
> > I am but what parameter do I give to Count? My entity model don't have
> > a comments field it is just connected through the view where I do {%
> > load comments %}?
>
> Immediately after posting my comment I understood that you actually
> can do that easily:
>
>    Entry.objects.annotate(cc=Count('comments')).order_by('-cc')
>
> In this case "comments" is a generic relation to the Comment model:
>
>    from django.db import models
>    from django.contrib.contenttypes import generic
>    from django.contrib.comments.models import Comment
>    class Entry(models.Model):
>        ...
>        comments = generic.GenericRelation(Comment,
>            content_type_field="content_type",
>            object_id_field="object_pk")
>
> However, denormalization would still be better in most cases.
> >
>
Any aggregation over generic relations is currently unsupported, it was
hoped this would make it into 1.1, but unfortunately some of the way SQL
works prevented this (since it requires us to change the underlying Query to
allow support for additional conditions on a join clause).

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to