Thursday, March 7, 2013

Re: queryset minimization

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 select_related:
https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related

_Nik

On 3/6/2013 11:18 PM, Fatih Tiryakioglu wrote:
> Hi all,
>
> Is there any shortcut (minimum db hit) for the following querysets:
>
> p = Person.objects.get(mail="person1@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 simply
> person (foreign key) and group (foreign key)
>
> #evaluating group of reg list.
> g = reg.group (for the every member of reg list)
>
> #and finally group name
> n = g.name (for the every member of g list)
>
> Which queryset or querysets hits the db, and how can I minimize it.
>
>
>
> Thanks.
> --
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate