Reputation: 81
I have two models using many2many relationship , but I can not make the correct query using one model to another. My code :
class Competition(models.Model):
name = models.CharField(max_length=30)
teams = models.ManyToManyField(Team, related_name='Com_Team')
class Team(models.Model):
name = models.CharField(max_length=30, unique=True)
But when I want to make a query like this:
com = Team.objects.get(id = 1).competition_set.all()
I'v been told that:
'Team' object has no attribute 'competition_set'
I just don't know what to do next... Thanks very much~~
Upvotes: 1
Views: 29
Reputation: 6767
You've told Django to call the attribute Com_Team
instead (with related_name='Com_Team'
):
Team.objects.get(id=1).Com_Team.all()
Upvotes: 4