I took this sample code here : 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
?
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!
精彩评论