On Tue, 2008-02-12 at 06:06 -0800, Roboto wrote:
> Hey all,
> 
> I guess I'm lazy with sql queries, so I've got a quick question.  I
> just pulled a set of results from a table that foreign_keys the User
> table.
> 
> But at the same time I'd like to access the get_profile data for each
> one of the users.
> 
> I know that if you do:
> print e.blog #hits the database
> print e.blog #will used the cached version
> 
> What if I do the following
> members = Access.objects.select_related().filter(xxx) #should grab all
> the associated user data here (but not the profile data)
> 
> And then in the template I do the following:
> 
> {% for member in members %}
> {{member.user.get_profile().gender}} # should hit the db right?
> {{member.user.get_profile().weight}} # will this hit the db again? or
> will it use a cached version?

Firstly, you'll notice when you try this, but you shouldn't have the
parentheses there. At some point in the attribute resolution process,
it's tested to see if the attribute is a callable and, if so, it's
called.

To answer the real question, a call to get_profile() on the User model
caches the object returned. So the second access there shouldn't hit the
database. See django/contrib/auth/models.py if you're interested.

Regards,
Malcolm

-- 
A conclusion is the place where you got tired of thinking. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to