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