Dear all,
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)
For 'through'-ing one more class you could use:
class Z(Model):
a = ForeignKey('A')
c = ForeignKey('C', through='A') # works because A.c exists
or:
class Z(Model):
a = ForeignKey('A')
c = ForeignKey('C', through='A__B') # works regardless of
whether A.c exists
I'm curious if other people would be interested in such a feature, or
maybe if something alike or better already exists, and whether there
are downsides that I miss.
Cheers, Roald
--
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.