tags:

views:

103

answers:

1

Fresh from the Djangobook tutorial using the Books app example, you have Book related to Author through a many-to-many relationship and Book related to Publisher. You can get a set of books associated with a publisher with p.book_set.all(), but what do you need to do to get a set of authors associated with a publisher (through the books published)?

This is the models.py as is: http://pastie.org/457781

Thanks!

+4  A: 

Something like that:

publisher = Publisher.objects.get(...)
authors = Author.objects.filter(book__publisher=publisher).distinct()
Alex Koshelev
yep, but s/published/publisher/ on the first row (or vice versa on the second one, but I think you mean the r-version;-).
Alex Martelli
works great. thanks!
rick