On Tuesday, December 8, 2015 at 3:16:20 AM UTC+2, Michael wrote:
>
> I have the same problem.
>
> I tried to use `extra` but then I can't filter so it's not the best.
>
> Anybody has more info or a workaround?
>

Come to think of it, we already have a workaround:
   Book.objects.annotate(author_cnt=RawSQL("(select count(*) from author 
where author.book_id = book.book_id)").
The fact that you can do subselects with models.RawSQL is something that a 
lot of users seem to miss. There are a couple of reasons why one shouldn't 
use RawSQL too much, like the way it hard codes column names and table 
aliases.

 - Anssi

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/a2a73387-3f90-4d21-bff8-f709694dd370%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to