Most efficient way to handle two level deep relationships

2007-04-06 Thread Mike H
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, avat

Re: Most efficient way to handle two level deep relationships

2007-04-06 Thread Benjamin Slavin
Hi Mike, You'll probably want to check-out select_related. [0] With that feature, you could use: posts = Post.objects.select_related().filter(thread__slug=thread_slug) If the copy of Django you're using is recent enough (I don't know if it's in 0.96), you can use the 'depth' argument... posts =

Re: Most efficient way to handle two level deep relationships

2007-04-06 Thread Mike H
Hi Ben, Thank you, I had overlooked that! It works exactly as I wanted it to! Mike On 4/6/2007, "Benjamin Slavin" <[EMAIL PROTECTED]> wrote: > >Hi Mike, > >You'll probably want to check-out select_related. [0] > >With that feature, you could use: >posts = Post.objects.select_related().filter(