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

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -