Created
October 28, 2010 12:04
-
-
Save martinsam/651211 to your computer and use it in GitHub Desktop.
User Perf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#don't multiply queryset for user.get_profile... | |
#coworkers is a queryset of User | |
coworkers_id = set([c.id for c in coworkers]) | |
from users_profiles.models import UserProfile | |
profiles = UserProfile.objects.filter(user__in=coworkers_id) | |
co_profiles = dict((u.id, u) for u in profiles) | |
for co in coworkers: | |
co.get_profile = co_profiles.get(co.id) | |
return coworkers |
Author
martinsam
commented
Oct 28, 2010
Via 'RawQuerySet', however, impossible to chain with "queryset" methods
return coworkers.objects.raw('SELECT * FROM auth_user INNER JOIN users_profiles_userprofile ON (users_profiles_userprofile
.user_id
= auth_user
.id
)')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment