开发者

Django - Selecting related set : how many times does it hit the database?

开发者 https://www.devze.com 2023-01-06 20:54 出处:网络
I took this sample code here : Django ORM: Selecting related set polls = Poll.objects.filter(category=\'foo\')

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消