The answer to this question may (and probably) already exist, but it's hard for me to find what to look for.
I have three models: Person, Group and Membership.
class Person(Contact):
first_name = models.CharField(_('first name'), max_length=200, blank=True)
last_name = models.CharField(_('last name'), max_length=200, blank=True)
class Organization(Contact):
title = models.CharField(_('title'), max_length=200)
members = models.ManyToManyField(Person, blank=True, through='Membership')
class Membership(models.Model):
person = models.ForeignKey(Person)
organization = models.ForeignKey(Organization)
position = models.CharField(max_length=64, blank=True)
I would like to get a list of people and have easy access to the group to which the person belongs, but not to the 1-to-1 relationship between the members and the character. It seems like the easiest way would be to create a get_memberships method inside Person that would return the membership if it was associated with anyone. Does this make sense, and is it wise to use this approach from within this model, or is there a better way to do this?
source
share