how to get opposite side of a foreign key relation in django -
i have following relationships:
class team(models.model): name = models.charfield(max_length=255) def players(self): ???? class player(models.model): user = models.onetoonefield(user, related_name="player") team = models.foreignkey(team)
from team object, players belong it.
how can values in opposite relationship?
this covered in detail in documentation on following relationships backward.
given team
object team
, players with:
team.player_set.all()
you can override player_set
name setting related_name parameter in foreignkey
definition.
Comments
Post a Comment