Re: Order_by number of foreign key joins

2009-03-10 Thread Adam N
You can do this by changing the Thing model: http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#reverse-generic-relations class Thing(models.Model): ... otherthing = generic.GenericRelation(OtherThing) For each thing, when you run thing.otherthing.all(), you'll

Re: Order_by number of foreign key joins

2009-03-10 Thread Alex Gaynor
On Tue, Mar 10, 2009 at 11:35 AM, Chris McCormick wrote: > > Hi, > > I want to do something like: > > Thing.objects.all().order_by("otherthing__count") > > So there's a many-to-many between Thing and Otherthing, and I want to get a > list of Things in the order of

Order_by number of foreign key joins

2009-03-10 Thread Chris McCormick
Hi, I want to do something like: Thing.objects.all().order_by("otherthing__count") So there's a many-to-many between Thing and Otherthing, and I want to get a list of Things in the order of most-otherthings joined - is there some easy, Djangoish way to do it, or should I create a new field in