Wednesday 15 June 2011

python - Django model multiple parameters in ForeignKey -



python - Django model multiple parameters in ForeignKey -

so have next code:

class team(models.model): shortname = models.charfield(max_length=255) fullname = models.charfield(max_length=255) desc = models.charfield(max_length=255) class match(models.model): team1 = models.foreignkey(team, related_name='team1') team2 = models.foreignkey(team, related_name='team2') start_date = models.datetimefield('date start') class bet(models.model): user = models.foreignkey(user) match = models.foreignkey(match) team = models.foreignkey(team) transaction = models.foreignkey(transaction) pub_date = models.datetimefield('date published')

what want parameter in bet pooints team1 or team2 in match, have tried following:

team = models.foreignkey(match.team1, match.team2)

however give me syntax error. proper way this?

your declaration indicates type of object populates attribute of model. in case, foreign key points team, right declaration should be

team = models.foreignkey(team)

on other hand, listing team twice seems inefficient, improve have selection field team selected in bet. 1 example:

team = models.charfield(max_length=1, choices=(('h', 'home team'), ('a', 'away team')))

then view code switch off of , determine of 2 teams show.

python django

No comments:

Post a Comment