On Jan 12, 2006, at 5:38 AM, Adrian Holovaty wrote:
On 1/11/06, Cheng Zhang <[EMAIL PROTECTED]> wrote:
class Entry(meta.Model):
submission_user = meta.ForeignKey(users.User)
class Friend(meta.Model):
myself = meta.ForeignKey(users.User, related_name="myself",
verbose_name="myself")
friend = meta.ForeignKey(users.User, related_name="friend",
verbose_name="friend")
How may I get a list of entry whose submission_user is in my friend
list, which is myself == my_id?
You can do it in two queries:
my_friends = friends.get_list(myself__exact=my_id)
entries.get_list(submission_user__in=[f.id for f in my_friends])
Adrian
Ya, that's Django's 101. I should be more specific that I'd like to
do it with only one get_list() call.
With the help on IRC, I learned how to use where/table to do this.
entries.get_list(**{'tables' :['friends',], 'where' :
['friends.friend_id = entrys.submission_user_id AND friends.myself_id
= my_id']})
- Cheng