Monday, January 23, 2012

Re: Joining tables

@bruno

Dint know that you can do lookups from OneToOne related models

Thanks

On Mon, Jan 16, 2012 at 8:00 PM, bruno desthuilliers <bruno.desthuilliers@gmail.com> wrote:
On Jan 16, 8:04 am, Arun P <arun....@gmail.com> wrote:
> Does this work?
>
> info =
> ExtraInformation.objects.filter(user__is_active=1,user__is_staff=0,user__is_superuser=0).order_by("popularity").select_related("user")
>
> users = map(lambda i: i.user, info)


That was for the "uselessly complicated and memory-hungry" method. Now
for the "simple lazy" method:

=> users = User.objects.filter(<you filters
here>).order_by("extrainformation__popularity")

@OP : You can add a select_related if you plan on using data from
ExtraInformation so you save on useless queries.

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




--
Digitally,
Arun Prabhakar

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

No comments:

Post a Comment