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

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 ?

Answers


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!


Need Your Help

Send a mobile number from default android dialer to my application

android

I have a application for calling an API for phone call,

Pass values to content page from programmatically added masterpage menuitem?

menuitem master-pages navigationbar content-pages

I'm working on a project that uses a master page and content pages. My masterpage a navigation bar: