class Member( models.Model ):
id = models.AutoField(unique=True, primary_key=True)
...
class Address( models.Model ):
开发者_Python百科 member = models.ForeignKey( Member )
I have the pk for a Member & can retrieve a Member; but I want to retrieve the possibly more than one Address(es) that point to that Member. How do I achieve that in django ?
Address.objects.filter(member=somemember)
or
Address.objects.filter(member_id=somemember_pk)
class Address( models.Model ):
member = models.ForeignKey(Member, related_name="addresses")
Then use member.addresses
.
精彩评论