On Sat, 2008-04-26 at 10:52 +0800, realfun wrote: > I am writing a simple Django App, the model is like this: > class MyPosts(models.Model): > > content = models.TextField() > > > class MyPostComments(models.Model): > > mypost = models.ForeignKey(MyPosts) > > comment = models.TextField() > Now I need to query the top10 most-commented posts. > > After look at the online document for hours I couldn't find out a way > to do it.
To do that directly with Django's ORM would require aggregate support, since you need a column that represents count(*) and some grouping. That support doesn't exist yet (it's a Summer of Code project). You might be able to cobble something together using extra(select=...), but, personally, I'd just use raw SQL to do this. When you know the query you want to execute, there's nothing wrong with just doing it in SQL. Regards, Malcolm -- Everything is _not_ based on faith... take my word for it. http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---