views:

34

answers:

1

I took this sample code here : http://stackoverflow.com/questions/853184/django-orm-selecting-related-set

polls = Poll.objects.filter(category='foo')
choices = Choice.objects.filter(poll__in=polls)

My question is very simple : do you hit twice the database when you finally use the queryset choices ?

+1  A: 

It will be one query, but containing an inner SELECT; if you want to do some debugging on that, you could either use the marvellous django-debug-toolbar, or do something like print str(choices.query) which will output the raw sql of your query!

lazerscience
Oh yeah ... I have heard once or twice about this `.query`, but I always forget ...Thanks for the answer !
sebpiq