Re: queryset minimization

2013-03-07 Thread Nikolas Stevenson-Molnar
Also, I strongly recommend reading through this document for an idea of when queries do and don't hit the database: https://docs.djangoproject.com/en/1.5/topics/db/optimization/ Additionally, take a look at django-debug-toolbar, which will show you all the queries that go into returning a view, ho

Re: queryset minimization

2013-03-07 Thread Nikolas Stevenson-Molnar
1. No, the two will execute identically. 2. No, `group` is loaded by select_related, and `name` is a field on group, so it's loaded when group is, unless you explicitly exclude it. 3. That's one query. However, if you're only grabbing the first result, select_related isn't even necessary... just do

Re: queryset minimization

2013-03-07 Thread Fatih Tiryakioglu
Thank you Nicolas, This works: reg = p.groupregistration_set.all().select_related('group') name = reg[0].group.name This also works: name = p.groupregistration_set.all().select_related('group')[0].group.name 1) Is there any difference? Which one is beter. 2) reg = p.groupregistration_set.all().

Re: queryset minimization

2013-03-07 Thread Nikolas Stevenson-Molnar
The biggest hit is probably going to be the reg.group call. You can optimize that by using select_related (), which will take what is currently 1 + (number of group registrations for the user) queries and turn it into 2 queries: reg = p.groupregistration_set.all().select_related('group') More on

queryset minimization

2013-03-06 Thread Fatih Tiryakioglu
Hi all, Is there any shortcut (minimum db hit) for the following querysets: p = Person.objects.get(mail="pers...@ex.com") p.password & form.password comparison and it is ok. #reversing to the person's groupregisteration, for example: reg = p.groupregistration_set.all() #groupregistratin model is