Thanks...

I'm perfectly comfortable with using foreign keys (and reverse) with
the django orm.  For basic joins this is fine.  For more advanced
queries involving complex aggregations (ie-reporting), the orm seems
to be pretty useless... looking at the generated sql shows this.  It's
It's quite easy to produce some nasty queries in loops.  I'm guessing
the if the simply query above can't be accomplished that I'm better
off trying straight sql or sql alchemy.

On Mar 15, 11:21 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Mar 15, 1:40 pm, jrs <j...@framemedia.com> wrote:
>
> > I see nothing on this page that is in the slightest bit related to my
> > question... Does anyone know if there is a way in the django orm to
> > accomplish my query above?
>
> > Thanks.
>
> As I explained, there's nothing different in a self-join than with any
> other sort of join. And so as of course you'll know, because you've
> read the documentation, you can always access a related object via the
> ForeignKey field:
>   accountinstance = Account.objects.get(pk=whatever)
>   accountinstance.parent_account
>
> If (for performance reasons) you need to get both with a single query,
> use select_related():
>   accountinstance = Account.objects.select_related().get(pk=whatever)
> --
> DR.

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

Reply via email to