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 get all
the otherthings.  You can count over that, etc...

If you look at my other post, if you have a list of things, and you
want all the otherthings for that list, you need to loop over each
thing and get the otherthing and then dedupe.  I'm looking for a
solution to that but at least the reverse generic relation gets you
farther down the line.

On Mar 10, 12:35 pm, Chris McCormick <ch...@mccormick.cx> 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 most-otherthings joined - is there some easy,
> Djangoish way to do it, or should I create a new field in Thing which holds 
> the
> number of Otherthings it's joined to?
>
> Chris.
>
> -------------------http://mccormick.cx
--~--~---------~--~----~------------~-------~--~----~
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