On 3/18/06, Ned Batchelder <[EMAIL PROTECTED]> wrote: > I want to select objects based on their relationships with related > objects, but I don't seem to be able to do it, because I'm trying to use > a foreign key in the "wrong" direction. For example, in the Polls and > Choices model, I can do this (from the docs): > > choices.get_list(poll__slug__exact="eggs") > > This works because the Choice class has a poll ForeignKey. But I can't > get a list of polls based on the characteristics of choices: > > polls.get_list(choice__choice__exact="overeasy") # Doesn't work. > > Am I wrong? Please tell me there is a way to accomplish what I want.
Here's how I'd solve this particular problem: [c.get_poll() for c in choices.get_list(choice__exact='foo')] If you need to remove duplicates: dict([(c.get_poll(), 1) for c in choices.get_list(choice__exact='foo')]).keys() (The second example exploits the fact that dictionaries can't have duplicate keys.) The database API doesn't support this kind of "reverse" lookup in 0.91. Hope this helps! Adrian -- Adrian Holovaty holovaty.com | djangoproject.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---