Select two entries from foreign-key/one-to-one field

Viewed 11

So I have a Team class:

class Team(models.Model):
    name = models.CharField(max_length=255)
    players = models.IntegerField()

and I want to select team1 and team2 separately in Match class :

class Match(models.Model):
    team1 = models.OneToOneField(Team,related_name=team1 ,on_delete=models.CASCADE)
    team2 = models.OneToOneField(Team,related_name=team2, on_delete=models.CASCADE)
 

but I get error (Add or change a related_name argument to the definition for 'tournament.Match.team1' or 'tournament.Match.team2'.) what am I missing ?

1 Answers

Related name is a string argument. So in your model you have to change related_name = team1, to related_name = "team1"

Related