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

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -