Access child records in ManyToMany relationship

What is the correct approach to access the related objects for the given below models:

class Person(models.Model):
    name = models.CharField(max_length=128)

    def __str__(self):
class Review(models.Model):
    name = models.CharField(max_length=128)

    def __str__(self):

    def get_review_team(self):
        return self.reviewteam_set.all()
class ReviewTeam(models.Model):
    review = models.ForeignKey(Review, on_delete=models.PROTECT)
    team_one = models.ManyToManyField(Person, related_name='teamone')
    team_two = models.ManyToManyField(Person, related_name='teamtwo')

    def __str__(self):

How to access the

team_one and team_two

of ReviewTeam set from Review object.get_review_team?

Using values_list on the ReviewTeam set I am able to get the IDs but not the names.


The function get_review_team is going to return a queryset containing all the rows in ReviewTeam.

So, if you iterate over that queryset, each instance of ReviewTeam is going to give you access to team_one and team_two.

From the docs at Many-to-many relationships | Django documentation | Django, you would use the .all method to retrieve all members from either team. If you iterate over those entries, you have access to the individual names.