Message from discussion
Feature request: ForeignKey through parameter
Received: by 10.220.178.69 with SMTP id bl5mr2831862vcb.20.1288274580758;
Thu, 28 Oct 2010 07:03:00 -0700 (PDT)
X-BeenThere: django-developers@googlegroups.com
Received: by 10.220.77.158 with SMTP id g30ls218734vck.3.p; Thu, 28 Oct 2010
07:02:51 -0700 (PDT)
Received: by 10.220.202.69 with SMTP id fd5mr2824966vcb.24.1288274571277;
Thu, 28 Oct 2010 07:02:51 -0700 (PDT)
Received: by 10.220.202.69 with SMTP id fd5mr2824965vcb.24.1288274571257;
Thu, 28 Oct 2010 07:02:51 -0700 (PDT)
Return-Path: <jav...@guerrag.com>
Received: from mail-qw0-f47.google.com (mail-qw0-f47.google.com [209.85.216.47])
by gmr-mx.google.com with ESMTP id j5si117378vcs.4.2010.10.28.07.02.51;
Thu, 28 Oct 2010 07:02:51 -0700 (PDT)
Received-SPF: softfail (google.com: domain of transitioning jav...@guerrag.com does not designate 209.85.216.47 as permitted sender) client-ip=209.85.216.47;
Authentication-Results: gmr-mx.google.com; spf=softfail (google.com: domain of transitioning jav...@guerrag.com does not designate 209.85.216.47 as permitted sender) smtp.mail=jav...@guerrag.com
Received: by mail-qw0-f47.google.com with SMTP id 6so1921607qwd.20
for <django-developers@googlegroups.com>; Thu, 28 Oct 2010 07:02:51 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.229.236.194 with SMTP id kl2mr6727306qcb.74.1288274570712;
Thu, 28 Oct 2010 07:02:50 -0700 (PDT)
Received: by 10.229.73.18 with HTTP; Thu, 28 Oct 2010 07:02:50 -0700 (PDT)
In-Reply-To: <E7D9DBCF-4BFE-4594-A0DC-933E86A29BF9@gmail.com>
References: <E7D9DBCF-4BFE-4594-A0DC-933E86A29BF9@gmail.com>
Date: Thu, 28 Oct 2010 09:02:50 -0500
Message-ID: <AANLkTimh6-MpMxMNt0kDQ5hPkfMzxZKzsaUMTNnYK6kz@mail.gmail.com>
Subject: Re: Feature request: ForeignKey through parameter
From: Javier Guerra Giraldez <jav...@guerrag.com>
To: django-developers@googlegroups.com
Cc: Roald de Vries <ro...@go2people.nl>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Thu, Oct 28, 2010 at 2:54 AM, Roald de Vries <downa...@gmail.com> wrote:
> I quite often reference foreign keys of foreign keys of foreign keys...
> Wouldn't it be nice to have a 'through'-parameter for ForeignKey's?
>
>
> =C2=A0 =C2=A0class A(Model):
> =C2=A0 =C2=A0 =C2=A0 =C2=A0b =3D ForeignKey('B')
> =C2=A0 =C2=A0 =C2=A0 =C2=A0c =3D ForeignKey('C', through=3D'B', related_n=
ame=3D'a_set')
>
> =C2=A0 =C2=A0class B(Model):
> =C2=A0 =C2=A0 =C2=A0 =C2=A0c =3D ForeignKey('C')
i'd love such a feature too, but i think a better syntax could be
something like:
class A(Model):
b =3D ForeignKey('B')
c =3D ForeignKey('B__c', related_name=3D'a_set')
class B(Model):
c =3D ForeignKey('C')
where the second part of the reference is the name of the field ('c'
in this example), not the model class ('C')
--=20
Javier