Re: Feature request: ForeignKey through parameter
On Thu, Oct 28, 2010 at 2:54 AM, Roald de Vrieswrote: > 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? > > class A(Model): > b = ForeignKey('B') > c = ForeignKey('C', through='B', related_name='a_set') > > class B(Model): > c = ForeignKey('C') > > > The advantages of a field A.c wrt a property A.c: > - it creates a reverse relation, so C.a_set becomes available > - c becomes queryable: A.objects.filter(c=x) Hi Roald, Thanks for suggesting this. I don't think it's worth implementing, though, because you can already query across multiple foreign-key relationships like this: A.objects.filter(b__c__exact=x) As for making C.a_set available, I'd suggest just doing A.objects.filter(b__c__exact=c_instance) in your view, and that'll get the job done. Adrian -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Re: Feature request: ForeignKey through parameter
On Thu, Oct 28, 2010 at 9:15 AM, Roald de Vrieswrote: > On first sight, I think I agree with you that the syntax is cleaner like > this, but I would choose for the through-parameter because it's more > consistent with the use of the through-parameter for ManyToManyField. but what if B has more than one ForeignKey('C') fields? -- Javier -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Re: Feature request: ForeignKey through parameter
On Oct 28, 2010, at 4:02 PM, Javier Guerra Giraldez wrote: On Thu, Oct 28, 2010 at 2:54 AM, Roald de Vrieswrote: 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? class A(Model): b = ForeignKey('B') c = ForeignKey('C', through='B', related_name='a_set') class B(Model): c = ForeignKey('C') i'd love such a feature too, but i think a better syntax could be something like: class A(Model): b = ForeignKey('B') c = ForeignKey('B__c', related_name='a_set') class B(Model): c = ForeignKey('C') where the second part of the reference is the name of the field ('c' in this example), not the model class ('C') On first sight, I think I agree with you that the syntax is cleaner like this, but I would choose for the through-parameter because it's more consistent with the use of the through-parameter for ManyToManyField. -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Re: Feature request: ForeignKey through parameter
On Thu, Oct 28, 2010 at 2:54 AM, Roald de Vrieswrote: > 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? > > > class A(Model): > b = ForeignKey('B') > c = ForeignKey('C', through='B', related_name='a_set') > > class B(Model): > c = ForeignKey('C') i'd love such a feature too, but i think a better syntax could be something like: class A(Model): b = ForeignKey('B') c = ForeignKey('B__c', related_name='a_set') class B(Model): c = ForeignKey('C') where the second part of the reference is the name of the field ('c' in this example), not the model class ('C') -- Javier -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.