This seems like something that should be doable, but I can't seem to
make it work.

Consider an example with these models:

class Book(models.Model):
  author = models.ForeignKey(Author)
  publisher = models.ForeignKey(Publisher)
  pub_date = models.DateTimeField()
  is_hardcover = models.BooleanField()
  pages = models.IntegerField()

class Author(models.Model):
 name = models.CharField(...)

class Publisher (models.Model):
  name = models.CharField(...)

I want to get a list of all of the books, authors and publishers that
were published in 2005 in hardcover with over 300 pages. So, this is
an easy queryset to create:

recent_books = Book.objects.filter(pub_date__year='2005',
is_hardcover= True, pages>300)

and I know that I can get them this way:
recent_authors =
Author.objects.filter(book__pub_date__year='2005',is_hardcover= True,
pages>300) .distinct()
recent_publisher =
Publisher.objects.filter( book__pub_date__year='2005',is_hardcover=
True, pages>300).distinct()

but that isn't very DRY.

I would like to be able to do something like:
recent_authors = Author.objects.filter(book in recent_books)

Can an equivalent be done?  How would you do it? Or alternatively, how
would you keep this code DRY?

Thanks in advance,
Dave
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to