henriquebastos/django-aggregate-if — pull request #5 by martsberger (2014-03-20 20:27:53+00:00)
Title: Allow only clause to refer to fields not already joined to

It should be possible to do a query like this:
```
publishers = Publisher.objects.annotate(jeff_books=Count('book', only=Q(book__contact__name__icontains='Jeff')))
```

This generates an error because the author table is not joined to. In this pull request, the `only` clause explicitly generates the necessary joins so that the above query will work.

Test included.