views:

151

answers:

0

Hey there, I've been looking through the site and trying to find something to help me, but I can't find anything. I'll begin with showing the models that relate to this:

class Game(models.Model):
    home_team = models.ForeignKey(Team, related_name='home_team')
    away_team = models.ForeignKey(Team, related_name='away_team')
    round = models.ForeignKey(round)

TEAM_CHOICES = ((1, '1'), (2, 'X'), (3, '2'),)

class Odds(models.Model):
    game = models.ForeignKey(Game, unique=False)
    team = models.IntegerField(choices = TEAM_CHOICES)
    odds = models.FloatField()
class Meta:
    unique_together = (("game", "team"),)

class Vote(models.Model):
    user = models.ForeignKey(User, unique=False)
    game = models.ForiegnKey(Game)
    score = models.ForeignKey(Odds)
class Meta:
    unique_together = (("game", "user"),)

This is the basic models, Team and Round are just Team names and round numbers (1,2,3,...) respectively.

To describe this, Game contains 2 teams and a round, Odds contains a Game, a choice and some odds, so each game has 3 odds, (for example -> 1, 1.8; X, 3.8; 2, 5.8), and Vote contains a User, a Game and a Score, so each User, for each game has one score (for example -> 1, 1.8 OR X, 3.8 OR 2, 5.8).

So what I'm looking for is to be able to add/edit Votes for each round (I guess I need to use formsets, but I'm having trouble with that)

To sum up, User logs into the site (this is no problem of course and is ready) and hits "vote for round 1" and up pops a form, label that displays a game and 3 options (1,X,2) like this if there are 4 games in round 1:

Game 1 X 2
Game1 () () ()
Game2 () () ()
Game3 () () ()
Game4 () () ()