On Wed, Sep 24, 2008 at 9:25 AM, Evgeny <[EMAIL PROTECTED]> wrote:
>
> Hi,
> There's an object hierarchy: A references B, B references C.
> "references" means foreign key.
> Is there a nice Django way to select all C objects which are
> grandchilds of given A with one query? Somethink like
>
> select C.* from C
> join B on B.id = C.id_b
> join A on A.id = B.id_a
> where A.id = 1
>
> i.e. in Django terms get all C objects which are children of
> A.objects.get(id=1).B_set.all()

You probably mean this:
C.objects.filter(id_b__id_a__exact=1)

Your code and your description do not match though. You write
'A references B', but you've got a foreign key from B to A (field id_a)
Maybe you meant A is referenced by B?


Matthias

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to