I'm creating a Person Group and Membership as described in django docs for intermediate model.
class Person(models.Model):
name = models.CharField(max_length=128)
def __unicode__(self):
return self.name
class Group(models.Model):
name = models.CharField(max_length=128)
members = models.ManyToManyField(Person, through='Membership')
def __unicode__(self):
return self.name
class Membership(models.Model):
person = models.ForeignKey(Person)
group = models.ForeignKey(Group)
date_joined = models.DateField()
invite_reason = models.CharField(max_length=64)
It is possible to access the Person from a Group object with:
>>>MyGroup.members.name
Does Django creates another query to fetch the Person?
Can I access the date_joined
field from a Group object?
The thing that confuses me is that I would expect to get the person name field with:
>>>MyGroup.members.person.name
What happens if a Person has a field 'name' and also the intermediate model have a field 'name'.