Hi all,
I'm implementing a simple forum which looks like this, but I'm
concerned about how many queries are going to get run, and if there is a
more efficient way o structuring my view :
from django.contrib.auth.models import User
class Profile(models.Model):
... some attributes here, avatar, tagline etc. ...
user = models.ForeignKey(User)
class Post(models.Model):
.. some forum info here, not important ...
poster = models.ForeignKey(Profile)
So, say I am displaying a list of posts, and as part of the template I
want to output some information from their profile, and their username
which is stored in their user record. My view code looks something like
this :
def thread(request, thread_slug):
posts = Post.objects.filter(thread__slug=thread_slug)
return render_to_response('posts.html',{'posts': posts,})
and my template looks like this:
{% for post in posts %}
{{ post.poster.user.username }} said {{ post.content }}
{% endfor %}
Is accessing the username from the user inside the poster inside the post
going to trigger a query for every post I display? Is there a better way
to access information that's a few levels deep like that?
Thanks for any pointers you can give!
Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---