Alex,

Good thought.  Not as crisp as I would like, but it should do the
trick.

Thanks,
Dave

On Mar 24, 6:18 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> How about recent_authors = Author.object.filter(book__pk__in=[b.pk for
> b in recent_books]).distinct()
>
> That can probably be done without the list comprehension but this
> should work.
>
> On Mar 24, 7:23 pm, davenaff <[EMAIL PROTECTED]> wrote:
>
> > 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 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to